2

When, while typing a question or an answer, a block of code is introduced via <pre><code>...</code></pre> one usually can have html-tags inside that block of code like <b>...</b> or <i>...</i> or <sub>...</sub> for doing one's own formatting/highlighting with some portions of the code displayed within the block of code.

On the main-site syntax-highlighting being enabled (which is the default) currently leads to one's own highlighting/formatting via html-tags like <i>...</i>, <b>...</b>, <sub>...</sub>, etc within code-blocks of pattern <pre><code>...</code></pre> being ignored.

To me this makes sense.
I think giving one's own highlighting to code while features for automatic syntax-highlighting are available usually is not good practice.

But in my humble opinion TeX is a special case:

  • When explaining things you sometimes cannot easily get around the need of writing "code" which actually does not refer to source-code as it would occur in a .tex-input-file but does refer to tokens in the token-stream after tokenization, so that sometimes you like to indicate a property of a token, e.g., a category code or the like, via subscript-text.

    I see two approaches to the matter of (ab?) using code-blocks for giving a visual impression of larger sequences of TeX-tokens:

    1. Turning off syntax-highlighting completely. Then tags <b>...</b> or <i>...</i> or <sub>...</sub> etc within <pre><code>...</code></pre>-blocks are not ignored.
    2. Somehow getting the syntax-highlighting into not ignoring tags <b>...</b> or <i>...</i> or <sub>...</sub> etc while syntax-highlighting is turned on.

    In this situation I tend to prefer the first approach: Syntax-highlighting is focused on displaying a piece of TeX-code as it might occur in a text-file which is to be read/processed by the TeX-program.
    The scenario described by me actually is not about displaying a piece of TeX-code as it might occur in a text-file. It is about sort of abusing blocks of code for giving sort of a visual impression of the token-stream which actually is not source code but is a sequence of data structures which exist while TeX is running.

  • Sometimes I like to display (portions of) the content of a .log-file, hereby emphasizing specific messages, e.g., by having them in boldface. In such situations I'd rather have the .log-file displayed as a block of code without automatic syntax-highlighting.

My first question is: How can I turn off syntax highlighting?

(When doing <!-- language: lang-none --><pre><code>...</code></pre>, right now, when typing in the preview window, syntax highlighting seems to be turned off and tags <b>...</b> or <i>...</i> or <sub>...</sub> etc seem to be obeyed. But when you post the answer, unfortunately the syntax highlighting is there after all and tags <b>...</b> or <i>...</i> or <sub>...</sub> etc are not obeyed any more.
So the preview is not correct but misleading.
I think this might be a bug.)

My second question is: How can I have tags <b>...</b> or <i>...</i> or <sub>...</sub> etc inside <pre><code>...</code></pre> not being ignored while syntax-highlighting is turned on?

(Not my favored approach, however. When not displaying TeX-code as it might occur in a text-file but giving a visual impression of tokens that exist while the TeX-program is running, one should not pretend the displaying of TeX-code as it might occur in a text-file by also applying the automatic syntax-highlighting for such code.)

My third question is: What other/better approaches do you suggest for displaying large lists of TeX-tokens, not TeX-source-code?

For example, my answer to the question "Expandable test for an empty token list—methods, performance, and robustness" describes three scenarios of how the expansion-cascade initiated due to a piece of code might work out. Each description is interspersed with code-listings. But expansion-cascades in TeX actually refer to tokens, so actually these code-listings are not about pieces of TeX-code that might occur in a .tex-file but are about sequences of tokens. In the expansion-cascade the fact plays a rôle that applying \string to an explicit {-character-token of category 1(begin grouping) returns an explicit {-character-token of category 12(other). So in some places subscript is used for noting category-codes. I thought about additionally putting a frame around each sequence that makes up a token via abusing the <kbd>-tag, e.g., \secondoftwo{12 instead of just \secondoftwo{12, but

  • that would make a lot more code:
    <pre><code>...<kbd>\secondoftwo</kbd><kbd>{<sub>12</sub></kbd>...</code></pre>
    instead of
    <pre><code>...\secondoftwo{<sub>12</sub>...</code></pre>.
  • the font in use with the <kbd>-tag is of considerably smaller size than the font in use when just displaying code—this affects readability.

My fourth question is: Would the idea of introducing another "syntax-highlighting-language" not for displaying TeX-code as it might occur in a .tex-input-file but for displaying larger lists of TeX-tokens that only exist while TeX is running make sense?


Please don't tell me that blocks of code are to be introduced via ``` or via indenting by four space characters unless you know a way of having subscript/bold/italic text in blocks of code that are introduced in one of these ways. ;-)

1 Answer 1

4

This answer refers to the first question:

I found out:

Nowadays you can work only with the tag
<!-- language-all: lang-⟨language⟩ -->.

The tag
<!-- language: lang-⟨language⟩ -->
does not work any more.

So <!-- language: lang-none --><pre><code>...</code></pre> or <pre><code><!-- language: lang-none -->...</code></pre> for turning off sytax-highlighting with a single block of code don't work out any more although in the preview which is shown while editing this is not indicated.

But you can still switch the syntax-highlighting-language to "none" for all subsequent code-blocks by placing <!-- language-all: lang-none --> before the code-block in question.

After that code-block you can switch back to syntax-highlighting-language "latex" for all subsequent code-blocks via <!-- language-all: lang-latex -->.

It seems tags of pattern <!-- language-all: ... --> must be on a line on their own.



For example


With the code
<!-- language-all: lang-latex -->
```
\firstofone{\macro{X}}%
```
expansion of `\firstofone` leads to the following tokens
being delivered to TeX's gullet:

<!-- language-all: lang-none -->
<pre><code>\macro<sub>(control&nbsp;sequence&nbsp;token)</sub><!--
line too long, thus use html-comment for breaking it
-->{<sub>(1)</sub>X<sub>(11)</sub>}<sub>(2)</sub></code></pre>
<!-- language-all: lang-latex -->

yields:


With the code

\firstofone{\macro{X}}%

expansion of \firstofone leads to the following tokens being delivered to TeX's gullet:

\macro(control sequence token){(1)X(11)}(2)

You must log in to answer this question.

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