2

It has been argued to me that it is dangerous to change the hyphen - as a normal character in style files because one might break a lot of code, negative numbers, overbar accents, table markup, ... all likely to break.

Doesn't the underscore with \ExplSyntaxOff also lead to similar problems ?

I am starting to think that originally disallowing underscores _ in names was in actuality a design mistake.

5
  • 2
    No, underscore has none of those problems as it is not part of the syntax of TeX the way - is. - is part of the syntax of a number. _ has been used in l3 code since about 1990 we really do have a lot of experience here Commented Sep 27, 2023 at 20:15
  • 3
    allowing underscores in names would make a lot of math a lot harder to enter (and certainly couldn't be done now without breaking a large part of the existing corpus of tex documents) \alpha_1, \alpha_2,... requires _ not to be a letter or it is the undefined command \alpha_ not a subscript. Commented Sep 27, 2023 at 20:25
  • 1
    Right. Then the use of \ExplSyntaxOff (i.e. disallowing _) is primarily meant for making the entering of math commands in documents easier.
    – Veak
    Commented Sep 27, 2023 at 20:56
  • 2
    math was the start of tex, Knuth's decision to use ^ and _ goes back to the mid 70's it's theoretically changeable but not if you want end users to recognise the syntax as tex. Commented Sep 27, 2023 at 21:04
  • 1
    That's quite fair enough.
    – Veak
    Commented Sep 27, 2023 at 21:20

2 Answers 2

8

TeX sets the category code of a character when it is tokenized. That means that if we have code using a 'letter' from outside a-zA-Z, we only need to worry about what's happening where the catcode is set. Thus for example in expl3:

\cs_new:Npn \foo #1 { \__mypkg_internal_foo:n {#1} }

defines \foo, which will use \__mypkg_internal_foo:n even if we have changed the catcode of _.

The only issue in normal TeX usage with _ begin a 'letter' is that it's used for subscripts. So if we want to produce a subscript within expl3 code we need to 'generate' the correct character token: \char_generate:nn { `\_ } { 8 }

We could do the same with other chars: the obvious one is @, used by plain TeX and LaTeX2e. Using - is more 'interesting' as in an expression such as \count10=-5\relax, TeX requires - is 'other'. That is a real issue, and is one reason in expl3 we've not yet found a way to 'set' the catcode of all potentially-active chars.

1
  • 1
    This has been an answer at an excellent level.
    – Veak
    Commented Sep 27, 2023 at 20:59
2

Not really. The main two purposes of underscores in the LaTeX syntax are:

  1. Math subscripts, e.g. \alpha_i
  2. File address and URLs such as my_file.tex

As expl3 is mainly intended for actual programming, math content is rare, and in the few cases where you need to write something like αi, you can type\alpha\sb{i} instead of \alpha_i. So the first use of underscores doesn’t really cause issues within expl3. And as far as I know, the second use of underscores is not affected by the changing of catcodes within expl3, so this doesn’t really cause issues either.

1
  • 2
    Good elaboration. I making good sense of things now. Then _ does not cause many problems (there are various workaround), unlike - which would be problematic.
    – Veak
    Commented Sep 27, 2023 at 21:02

You must log in to answer this question.

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