question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(LaTeX) Matching TeX magic comments should be case insensitive

See original GitHub issue

Describe the issue

TeX magic comments are, in most editors, case insensitive, so both lines below are interpreted:

% !TeX program = lualatex
% !TEX encoding = UTF-8
%   ^ note e vs. E here

but the MAGIC_COMMENT rule only highlights the TeX (first) line:

https://github.com/highlightjs/highlight.js/blob/2dd87a6ef58c8c886dd209076aa6661ffae89577/src/languages/latex.js#L106-L111

Screenshot from 2021-06-14 11-30-00

Which language seems to have the issue?

latex

Are you using highlight or highlightAuto?

I don’t know? highlight I think because the language is specified explicitly.

Sample Code to Reproduce

% !TeX program = lualatex
% !TEX encoding = UTF-8
%   ^ note e vs. E here

Expected behavior

In the sample above, lines 1 and 2 should be highlighted as MAGIC_COMMENT, and line 3 should be a regular COMMENT:

Screenshot from 2021-06-14 11-32-46

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
schtandardcommented, Jun 18, 2021

@PhelypeOleinik Thanks a lot for your research! I mostly agree with your conclusions, except for two minor points. I don’t feel strongly about either of them, though.

  • I would omit the optional space after the !. I have never seen this and according to your list only LaTeX-Workshop supports it. I guess the idea is to allow %! TeX and I sympathise with your point about remembering where spaces are allowed, but this feels like too much of a niche case to me.
  • I agree that case mixing like tEx is a bit absurd, but should we maybe allow tex and bib? This seems a reasonable spelling to me (for the editors that support them) and is also in line with the “just use lowercase” default many technical users may be used to.

About the ^: At least TeXStudio accepts magic comments anywhere in the document with no restriction of being the only thing on that line. (I didn’t test any other editors.) While I myself only ever use them on the first lines of a document (with no indentation), I wouldn’t make that a requirement for highlighting.

With all this my suggested regex would be % ?!(?:T[eE]X|tex|BIB|bib). Any comments? (No pun intended.)

0reactions
PhelypeOleinikcommented, Jun 18, 2021
* I would omit the optional space after the `!`. I have never seen this and according to your list only LaTeX-Workshop supports it. I guess the idea is to allow `%! TeX` and I sympathise with your point about remembering where spaces are allowed, but this feels like too much of a niche case to me.

Sounds reasonable. Given the plethora of different implementations, some level of restriction is good, so I’m fine with no space after !.

* I agree that case mixing like `tEx` is a bit absurd, but should we maybe allow `tex` and `bib`? This seems a reasonable spelling to me (for the editors that support them) and is also in line with the "just use lowercase" default many technical users may be used to.

Sounds good too.

With all this my suggested regex would be % ?!(?:T[eE]X|tex|BIB|bib). Any comments? (No pun intended.)

Go for it! (the regex, not the pun 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

compiling - When and why should I use % !TEX TS-program ...
My comments apply in principle to both TeXShop and TeXworks. ... 〈program〉 should be one of the programs set up in TeXworks and...
Read more >
Advanced Usage | LTeX - valentjn
Magic comments are case-insensitive (except for the setting values), and the spaces in the magic comment line can be any amount of whitespace, ......
Read more >
TeXstudio : user manual
Before using TeXstudio, you should configure the editor and latex related ... save the language of the file TeXstudio supports a special "magic...
Read more >
User manual - TeXstudio
Here we assume that TeXstudio and a LaTeX-system are already installed on ... a case-insensitive search, a global search (continue after the first...
Read more >
The SageTEX package
you that using graphics well is not easy, and no LATEX package or ... matched up to Sage's baked-in SageTEX support, so you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found