0

I am using hyphen as a letter for command names. But I allow users to rename them if necessary. Then use \catcode`-=11. Suppose I keep the hyphen as a letter in command names, I wonder if users could encounter problems if they keep \catcode`-=11 for the entire document.

David Carlisle
  • 757,742
Veak
  • 1
  • Briefly looking around there are a few packages that parses token list consist of - https://tex.stackexchange.com/questions/112831/typesetting-transition-metal-cluster-in-mhchem/112838#112838 https://tex.stackexchange.com/questions/323342/mfuhyphentrue-is-undefined-control-sequence/323348#323348 – user202729 Sep 27 '22 at 00:32
  • did you mean to ask if there would be problems if they keep catcode 11 ?? – David Carlisle Sep 27 '22 at 07:13
  • Yes. that is what I meant. – Veak Sep 27 '22 at 09:47
  • You could have edited to fix the question (I did it now:-) – David Carlisle Sep 27 '22 at 11:21
  • Have started editing my questions straight away after seeing comments. Thank you so very much David. – Veak Sep 27 '22 at 11:23

2 Answers2

3

Setting the catcode of the hyphen to letter in a document is a very bad idea. A few examples for a test:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\catcode`-=11

\tikz\draw(0,0)--(1,0); %errors

some long-word-with-hyphenation %errors

\setlength{\parindent}{-1cm} %errors \end{document}

which errors with

! Package tikz Error: Giving up on this path. Did you forget a semicolon?.

See the tikz package documentation for explanation. Type H <return> for immediate help. ...

l.86 \tikz\draw(0,0)- -(1,0); ? ! Undefined control sequence. l.88 some long-word -with-hyphenation ? ! Undefined control sequence. l.88 some long-word-with -hyphenation ? ! Undefined control sequence. l.88 some long-word-with-hyphenation

? ! Missing number, treated as zero. <to be read again> - l.90 \setlength{\parindent}{-1cm}

? ! Illegal unit of measure (pt inserted). <to be read again> - l.90 \setlength{\parindent}{-1cm}

Ulrike Fischer
  • 327,261
2

Some LaTeX constructs that fail if - is catcode 11:

\documentclass[a4paper]{article}

%\catcode`-=11

\usepackage{array}[2021-01-01] \usepackage{textgreek}

\begin{document}

aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc aaa-bbb-ccc

$ \cos-x=\cos x$

$\alpha-\beta$

\textalpha-rays

\verb-\SomeCommand-

\begin{tabular}{lll} 1&2&3\ \cline{2-3} a&b&ct \end{tabular}

\end{document}

If you use - internally like @ classically or _ in expl3 you could provide \DashLetterOn and \DashLetterOff like \makeatletter/\makeatother to allow local access to that syntax in the preamble, but do not use - for commands intended for document use.

David Carlisle
  • 757,742