6

This is retrocomputing. We sometimes need to type code in old languages.

In particular, if I am to be able to write Algol in the publication language, I need a bold font. But I also need my text to be laid out as typed - line breaks and indentation included.

It seems that code-style and bold do not go together.

    **comment** this makes me sad;

I discovered I can get line-breaks to remain outside of a code block by having a couple of spaces before the end of line, but I have not yet found a way to keep indentation.

Is there some way to type Algol correctly? (Without resorting to stropping conventions)

For what it's worth, I don't need a monospaced typeface. That wasn't a necessary thing in Algol publications.

1

2 Answers 2

8

Type HTML directly.

<pre><code>    <b>comment</b> this makes me sad;
second line
    with <i>indentation</i> too!
</code></pre>

produces:

    comment this makes me sad;
second line
    with indentation too!

This isn't a good solution, but it works. The limitations of the medium, and all that.

1
  • 1
    Ah. Easy enough. Thanks.
    – dave
    Feb 1, 2022 at 23:46
4

As an alternative to formatting keywords with raw HTML, you could use Unicode โ€œmathematical boldโ€ characters.

    ๐œ๐จ๐ฆ๐ฆ๐ž๐ง๐ญ this makes me sad;
๐ข๐ง๐ญ๐ž๐ ๐ž๐ซ ๐ฉ๐ซ๐จ๐œ๐ž๐๐ฎ๐ซ๐ž square(n);
    ๐ฏ๐š๐ฅ๐ฎ๐ž n; ๐ข๐ง๐ญ๐ž๐ ๐ž๐ซ n;
    square := n ร— n;
๐ฉ๐ซ๐จ๐œ square = (๐ข๐ง๐ญ n) ๐ข๐ง๐ญ :
    (n ร— n);

Unlike some other uses of Unicode mathematical bold (bypassing the lack of availability of formatting markup, especially when shitposting), this is arguably a correct use of those characters: they were meant to be used when writing mathematical notation, where what would otherwise be purely stylistic formatting may carry semantic meaning. To the extent you can consider computer code a form of mathematical notation (which, I think, is not that much of a stretch), this is pretty much exactly what happens here.

Advantages of this approach: the bolding is preserved even when you copy the code as plaintext (unlike HTML formatting), and it may be easily converted to stropped form via little more than search-and-replace. Disadvantages: some systems may lack the necessary font support to display the characters, and even on those that do support them, the characters may render as proportionally-spaced, even if the ambient font is fixed-width, which means column-aligned spacing is going to be spoiled. Also, some poorly-written screen readers will not be able to read it.

Since inputting those characters can be a hassle, hereโ€™s a short, hastily-written user script to make that easier (known to work on Firefox 91 ESR with Greasemonkey):

// ==UserScript==
// @name     ๐€๐ฅ๐ ๐จ๐ฅ๐ข๐ณ๐ž๐ซ.
// @grant    none
// @match    https://retrocomputing.stackexchange.com/*
// @match    https://retrocomputing.meta.stackexchange.com/*
// ==/UserScript==

const embolden = text => {
  text = text.replace(/[A-Z]/g, c =>
    String.fromCodePoint(c.charCodeAt(0) - 0x41 + 0x1d400));
  text = text.replace(/[a-z]/g, c =>
    String.fromCodePoint(c.charCodeAt(0) - 0x61 + 0x1d41a));
  text = text.replace(/[0-9]/g, c =>
    String.fromCodePoint(c.charCodeAt(0) - 0x30 + 0x1d7ce));
  return text;
};

const link = document.createElement('a');
link.accessKey = ';';
link.addEventListener('click', ev => {
  const textarea = document.querySelector('input:focus, textarea:focus');
  if (!textarea || textarea.value == null)
    return;
  let text0 = textarea.value.substring(
    textarea.selectionStart, textarea.selectionEnd);
  if (!text0)
    text0 = prompt('Enter text');
  const text1 = embolden(text0);
  const cur = textarea.selectionStart;
  textarea.focus();
  document.execCommand('insertText', false, text1);
  textarea.selectionStart = cur + (text0 ? 0 : text1.length);
  textarea.selectionEnd = cur + text1.length;
});
document.body.appendChild(link);

After installing the script with your favourite method of instaling user scripts, press Alt+; or Alt+Shift+; (this may vary depending on your browser) to activate and enter the ALGOL keyword in ASCII characters. The script should replace ASCII letters and numbers within the selected text with their mathematical bold counterparts. With an empty selection, it will prompt you for the word to insert.

10
  • 1
    To enter such characters, I think I'd have to copy each character individually from a repertoire. (Just like cold-metal typesetting!) This seems laborious. Am I missing something?
    – dave
    Feb 2, 2022 at 13:04
  • You could write a script to handle that automatically, itโ€™s just a matter of piecewise shifting certain code point ranges: [U+0030..U+0039] โ†’ [U+1D7CE..U+1D7D7], [U+0041..U+005A] โ†’ [U+1D400..U+1D419], [U+0061..U+007A] โ†’ [U+1D41A..U+1D433] . But yeah, otherwise that part is something of an unsolved problem. Feb 2, 2022 at 13:40
  • 1
    You could write a script -- I'm not that kind of programmer :-)
    – dave
    Feb 2, 2022 at 14:50
  • You are not the kind of programmer who knows how to do such things, or not the kind of programmer who bothers? Feb 2, 2022 at 15:04
  • The former. Distinctly non-webby.
    – dave
    Feb 2, 2022 at 15:48
  • I was thinking about something that could be invoked from the command line, or bound to a system-wide hotkey. But since you mentioned โ€˜webbyโ€™, a user script can also doโ€ฆ Feb 2, 2022 at 17:26
  • 1
    Please do not misuse mathematical bold. It works very badly - if at all - with screen readers
    – scruss
    Jul 17, 2022 at 15:58
  • @scruss Iโ€™d argue this is one of the few appropriate uses of those characters, and not a misuse at all. As opposed to using them for emphasis of running natural-language text, which would indeed be a ๐ ๐ซ๐š๐ฏ๐ž misuse. Jul 17, 2022 at 16:08
  • 2
    @user3840170 no; it is a blight on accessibility. Your "integer procedure ..." example would read as mathematical bold small i mathematical bold small n mathematical bold small t mathematical bold small e mathematical bold small g mathematical bold small e mathematical bold small r space mathematical bold small p mathematical bold small r ... and that's the first ten characters. You can't get people to change their screen readers: it's just the way it works
    – scruss
    Jul 17, 2022 at 22:59
  • 1
    The lack of attention to detail with which screen reader software is written is the real blight on accessibility. If a screen reader fails to render such characters in speech reasonably, then this is a bug, and bugs are supposed to be fixed, not excused and bent-over-backwards for. Aug 30, 2023 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .