&ensp in a monospaced font

A

Andy Fish

Hi,

I am trying to output some html in monospaced font, and I want spaces to
take up the same width as any other character. i thought this would be easy
for monospaced fonts - surely   and   would both be the same
width?

unfortunately not -   is narrower than other characters and   is
wider :-(

so how do i generate a sequence of normal width spaces?

I can't use the <pre> tag because there is HTML markup in the output - it's
not only plain text

Andy
 
T

tech578

Hi,

I am trying to output some html in monospaced font, and I want spaces to
take up the same width as any other character. i thought this would be easy
for monospaced fonts - surely &ensp; and &emsp; would both be the same
width?

unfortunately not - &ensp; is narrower than other characters and &emsp; is
wider :-(

so how do i generate a sequence of normal width spaces?

I can't use the <pre> tag because there is HTML markup in the output - it's
not only plain text

Andy

maybe &nbsp;
 
A

Andreas Prilop

I am trying to output some html in monospaced font, and I want spaces to
take up the same width as any other character. i thought this would be easy
for monospaced fonts - surely &ensp; and &emsp; would both be the same
width?

Some things are meaningless in monospaced fonts. Think of all the
characters that have "zero-width" in their names.
unfortunately not - &ensp; is narrower than other characters and &emsp;
is wider :-(

In *which* font?
It is also possible that the browser takes ensp and emsp
from some other font.
 
C

C A Upsdell

Andy said:
I am trying to output some html in monospaced font, and I want spaces to
take up the same width as any other character. i thought this would be easy
for monospaced fonts - surely &ensp; and &emsp; would both be the same
width?

Why would you think that?
unfortunately not - &ensp; is narrower than other characters and &emsp; is
wider :-(

Of course.
so how do i generate a sequence of normal width spaces?

Something I have done on occasion is user '0' characters where I want
spaces, but with the colour the same as the background, so they look
like spaces.
 
J

Jukka K. Korpela

Scripsit Andy Fish:
I am trying to output some html in monospaced font,

Do you mean you wish to present HTML markup visibly or audibly on the
page? Then a monospace font would normally be a good idea. I would
suggest using <code> markup together with a style sheet like
code { font-family: Consolas, "Courier New"; }
to reduce the risk that some poor default monospace font is used.
and I want spaces
to take up the same width as any other character.

A normal space, as well as a no-break space, has the same width as other
characters, when the font is monospace
i thought this
would be easy for monospaced fonts - surely &ensp; and &emsp; would
both be the same width?

What? Why would you use specific-width space characters (which are
poorly supported in fonts) _and_ ask them to have the same width as
other characters? Why would you use them at all?
so how do i generate a sequence of normal width spaces?

By using the SPACE character U+0020 as everyone else.
I can't use the <pre> tag because there is HTML markup in the output
- it's not only plain text

You have misunderstood the meaning of <pre>, and what else?

The real problem is probably very different from the picture we've got
so far. To avoid wasting more of everyone's time, post the URL.
 
B

Bergamot

Jukka said:
suggest using <code> markup together with a style sheet like
code { font-family: Consolas, "Courier New"; }
to reduce the risk that some poor default monospace font is used.

I suggest font-family:monospace; and let the user decide whether their
default is "poor". Mine isn't by a long shot.
 
D

dorayme

"Jukka K. Korpela said:
I would
suggest using <code> markup together with a style sheet like
code { font-family: Consolas, "Courier New"; }
to reduce the risk that some poor default monospace font is used.

Whenever I have tried this, at least on my Mac, the code looks
too faint (setting a font-weight can fix, but this might make
other alternative fonts for code too bold). It is the 'Courier
New' that is the trouble on my machine at least. The default
'Courier' does not do this. Courier looks fine.
 
T

Toby A Inkster

dorayme said:
Whenever I have tried this, at least on my Mac, the code looks too faint
(setting a font-weight can fix, but this might make other alternative
fonts for code too bold). It is the 'Courier New' that is the trouble on
my machine at least. The default 'Courier' does not do this. Courier
looks fine.

Agreed. Courier New is a horrible font -- very lightweight and hard to
read unless there is a lot of contrast between the font colour and
background colour. The serifs are too pronounced and there is very little
visual difference between l/1 and O/0.

Courier is slightly better -- it's a reasonable weight -- but still not
fantastic for reading as it suffers from Courier New's glyph shape
problems.

In my stylesheets, I'm now specifying:

font-family: "Consolas", "Bitstream Vera Sans Mono", "Andale Mono",
"Monaco", "Lucida Console", monospace;

for monospaced fonts. Virtually all Mac OS 9/X machines will have Andale
Mono or Monoco. Windows Vista machines will have Consolas; earlier Windows
will have Andale Mono or Lucida Console. Most Linux machines should have
Bitstream Vera Sans Mono these days.

Each of those fonts are very readable, smart-looking, sans serif mono
fonts. They all have good visual distinction between 0/O and I/l/1 (except
Lucida Console where there is little difference between 0/O) which makes
them very suitable for reading code.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 31 days, 22:48.]

Bottled Water
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
 
B

Bergamot

C said:
Something I have done on occasion is user '0' characters where I want
spaces, but with the colour the same as the background, so they look
like spaces.

I bet it sounds great in a screen reader. :-\
 
B

Bergamot

Toby said:
In my stylesheets, I'm now specifying:

font-family: "Consolas", "Bitstream Vera Sans Mono", "Andale Mono",
"Monaco", "Lucida Console", monospace;

Why bother?
for monospaced fonts. Virtually all Mac OS 9/X machines will have Andale
Mono or Monoco.

If you just used font-family:monospace what do you suppose they'll see?
Even if their default is Courier [New], if they hated it don't you think
they would have changed it by now?

Ditto for every other OS/font combination you listed.
Each of those fonts are very readable, smart-looking

But beauty is in the eye of the beholder. I have both Bitstream Vera
Sans Mono and Lucida Console, but your order will force Vera Sans on me
while Lucida Console is my default.

Why don't you just let the user decide what's most readable in a
monospace font?
 
E

Els

Bergamot said:
But beauty is in the eye of the beholder. I have both Bitstream Vera
Sans Mono and Lucida Console, but your order will force Vera Sans on me
while Lucida Console is my default.

Why don't you just let the user decide what's most readable in a
monospace font?

By your logic, we shouldn't add any background or text colour either,
as the user can set that themselves too - what if your webpage is
black on white, while they would have preferred red on blue?
 
B

Bergamot

Els said:
By your logic, we shouldn't add any background or text colour either,

By your logic, we should set absolute font sizes to go with those fonts.
as the user can set that themselves too - what if your webpage is
black on white, while they would have preferred red on blue?

Now we're getting carried away. :)

Don't you get tired of every other web page insisting you use Arial or
Verdana or whatever? Why don't more authors just use the generic
families instead of over specifying everything?

We all make such a big deal about user controlled font sizes, but
default fonts are pretty much totally ignored. :(
 
E

Els

Bergamot said:
By your logic, we should set absolute font sizes to go with those fonts.

Nope, I'd set relative font-sizes that I think go with the rest of the
page and the purpose, and the user can still resize them, *and* force
their own user stylesheet over mine :)
Now we're getting carried away. :)

Really :)
Don't you get tired of every other web page insisting you use Arial or
Verdana or whatever? Why don't more authors just use the generic
families instead of over specifying everything?

No, I don't get tired of that at all.
Have a look at these pages. Each of them please:
http://www.jasonsantamaria.com/
http://mezzoblue.com/
http://molly.com/
http://mappingtheweb.com/

See how each has a different font?
If you have them on your system, you should have seen Georgia, Lucida
Grande, Verdana and Trebuchet MS.

I'd get tired of seeing my own preferred font on every webpage while I
could be looking at diversity in typography.

And I don't get your "insisting we use Arial or Verdana or whatever".
They don't insist, they suggest. If you really want to have your
internet pages all in Verdana, just write your own stylesheet.
We all make such a big deal about user controlled font sizes, but
default fonts are pretty much totally ignored. :(

Which is a good thing :)
 
B

Bergamot

Els said:
No, I don't get tired of that at all.
Have a look at these pages. Each of them please:

Seems we don't hang out at the same types of web sites. No matter. For
every 1 site you name that *doesn't* use Arial as a first-choice font,
there are thousands that do.

I uninstalled Verdana, Comic Sans and a few other fonts long ago so I
wouldn't have to look at them. I don't like Arial, but can't get rid of
that one. Wish I could.
If you really want to have your
internet pages all in Verdana, just write your own stylesheet.

I don't necessarily want the same font on every page either. Sometimes a
serif goes better with a design, sometimes sans. The 2 together can be
quite nice, too, when used properly.
Which is a good thing :)

Matter of opinion.
 
A

ajfish

ok maybe I didn't make myself clear

i am using a monospaced font. on one line of the output i have
'abcde'; on the next line I have 'a' followed by 3 spaces followed by
'e'

I want the 'e' in the second line to appear underneath the 'e' in the
first line

if I use a normal space, the 3 spaces are collapsed into one; if I use
an m-width or n-width space, the spaces aren't the same width as
letters; if I use a non-breaking space, this stops the line breaking
(which is not the behaviour I want)

however, you (ant other posters) are right - I didn't realise you can
put other html codes inside a <pre> block - so that looks like the
best option to me

Andy
 
J

John Hosking

(e-mail address removed) wrote:

[using a different name but presumably as OP Andy Fish]
ok maybe I didn't make myself clear

No. But it's worse than that; you top-posted as a reply to Mr. Korpela.
:-O This shows a level of daring (some may assume rudeness) that might
draw a few high-temperature flames. Better to avoid top-posting.

Maybe you're all flustered because you're using GG in the office, when
you're supposed to be working? ;-)
i am using a monospaced font. on one line of the output i have
'abcde'; on the next line I have 'a' followed by 3 spaces followed by
'e'

I want the 'e' in the second line to appear underneath the 'e' in the
first line

Much clearer.
if I use a normal space, the 3 spaces are collapsed into one; if I use
an m-width or n-width space, the spaces aren't the same width as
letters; if I use a non-breaking space, this stops the line breaking
(which is not the behaviour I want)

Even clearer. Then how about: <p>abcde</p><p>a&nbsp; &nbsp;e</p> ?

That should give you both the spacing and a possible break. I believe
you'd get the same effect (but with two break possibilities) if you did:
<p>abcde</p><p>a &nbsp; e</p> . (Not tested in all browsers.)

It's only consecutive spaces that get collapsed.

Programmatically (or algorithmically), you'd add a regular space for the
first space between chars, then a &nbsp; for the second one, then a
space, then a &nbsp; etc. until you'd replaced all the missing positions
with spaces of either kind.

(Sign-off left deliberately, normally I'd snip it.)

The stuff below is what you should have either trimmed completely or
selectively commented on in-line.
Scripsit Andy Fish:
[actual exchange snipped]

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top