4

(Bear with me, I know that having characters which are not monowidth in a monospace font is somewhat counterintuitive, but there is a legit use case below.)

I have an application I've written where I need fixed-width hexadecimal characters so that my output can look like the below:

21 41 49 56 44 4d 2c 31 
2c 31 2c 2c 41 2c 42 35 
4e 62 54 66 50 30 3f 36 
66 64 57 36 56 33 69 4b 

It's very important that the columns stay perfectly aligned, so a monospace font is critical.

However, I don't need that much whitespace between the characters, and in fact it makes the UI harder to use because of the excess distance. As a result, I'd like to find a font where the non-whitespace characters will be of constant width, but where I can tune the whitespace like in the examples given in https://jkorpela.fi/chars/spaces.html.

Does such a beast exist?

3
  • 1
    Use tabs and adjust your tabulation stops. Anyway its hard to say as you are not saying what your encironment you are working in.
    – joojaa
    Aug 1, 2021 at 8:58
  • I believe there are fonts which on the whole are proportional, but which have fixed width numerals. Aug 1, 2021 at 12:34
  • 1
    There are proportional fonts that have alternative glyphs for monospaced digits ("tabular numbers"), but I don't think that that can apply to characters for use as hexadecimal digits. You also could consider creating your own font, perhaps starting from a freely modifiable one.
    – jamesdlin
    Aug 1, 2021 at 21:01

3 Answers 3

4

We don't know about the technical side of the "application you've written", but in some design software there are spaces of different widths, aside from the usual Space.

These work even for monospaced fonts, however I believe they are not built into the actual font file, but instead somehow emulated by the software (again not aware of how it works at the coding level).

Alternatively, you could experiment with a more condensed monospace font.

See this: What are the function of EM and EN spaces?

enter image description here

enter image description here

2
  • Very interesting. I have tried all the em and en unicode spaces with Courier New, but unsurprisingly they all map to a single em space. My software just shows a single string of plain, non-rich text, so it's somewhat rigid in this regard. I don't think there's any painless way to accomplish what I'd like aside from finding the right font. Aug 1, 2021 at 12:54
  • My understanding is that TeX and LaTeX don’t insert “space characters” at all, and make no reference to the font for those, and instead handle all the spacing themselves. Of course, it’s possible that this behavior changes when using a monospaced font (but then, even if it does, you can almost-certainly change it again in those systems).
    – KRyan
    Aug 1, 2021 at 14:48
2

It is extremely unlikely that a fixed width font has such a feature because it would allow the fonts to not align under themselves. Which is obviously not what the designer intended. But consider:

  1. For most pars there is even no need for such things since there is a character that has a unspecified width that can be adjusted by the user. This is the tab character. So even most rudimentary systems should allow you to map tab so that it does what you want.

    Nearly every system i have used allowed me to do so easily. Sometimes by just allowing me to define tab width or tabstops. Sometimes by drawing from a different point. Usually not as big deal as you think because all it really need is a wrapper with a loop.

  2. If you really must have a special space. Just take a open source font open it in fontforge and define said space. 15 minutes of work including dowload of fontforge.

    Though i would say that this is a really inferior workflow.

0

In indesign you can do this with tabs, "insert white space" or with a grep character style.

insert white space:

enter image description here

grep character style:

Use "/s" to match all spaces and increase the width using tracking in the character style.

enter image description here

5
  • I had to look up what InDesign is, lol. Are you saying that with InDesign I could create a custom font by modifying an existing monospace one? Aug 1, 2021 at 14:21
  • @KennSebesta it does not really matter what functionality the font has. All applications meant for typography have free sized spaces and tabulation features. The thing is your asking a XY problem. In this case you think that havong right space solves your problem. It probably would. But what your not looking at is that nearly every system out there has a mechanism fortypographical adjustment. If you ask on a graphics design forum then you get an answer from their perspective. But if you were just to say what system you are programming in then people would tell how to adjust the program.
    – joojaa
    Aug 1, 2021 at 14:51
  • @joojaa I'm afraid I don't understand you, but I apologize if I brought offense as that was not my intention. I am writing an open-source cross-plaform serial terminal, gitlab.com/kubark42/AeroTerm, and I am using a plain text widget because it has all the functionality I need. It will support any font I throw at it, and so if I only cared about space width I could use a variable-width font and then use unicode to accomplish what I want. However, I also need text to align, which requires monospace. As it's hex, I only care about the numbers 0-9 and the letters A-F and a-f. Aug 1, 2021 at 15:05
  • @KennSebesta QT has ways to deal with this internally no need for font. See stackoverflow.com/questions/13027091/…
    – joojaa
    Aug 1, 2021 at 15:14
  • Interesting. I had no idea that was a possibility, nor had I considered hacking the tab to serve as whitespace. Nice! FWIW, I'm not using QTextEdit, but a TextArea in QML, so it inherits from QML's TextEdit. Fortunately, the Qt devs made tabStopDistance available via the QML interface. Unfortunately, even when set as a double it truncates to an int, whereas the font pixel width is a real, so this cool hack does not work in this context. I will try to force my font size to be an integer width, and I will also submit a bugreport to Qt Aug 1, 2021 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.