7

Background information on my computing setup: MacBook Air (late-2019 model), MacOS 11.2.3 "Big Sur", MacTeX2021 with all updates current.

Consider the following MWE:

\documentclass{article}
%\obeylines
\begin{document}
abc
\end{document} 

It (unsurprisingly) compiles fine under pdfLaTeX, XeLaTeX, and LuaLaTeX. In contrast, if one removes the % comment character before \obeylines, one gets the following error messages:

  • Under pdfLaTeX:

    ...
    (/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def
    ! Missing \endcsname inserted.
    <to be read again> 
                       ^^M
    l.29   {l3backend-pdftex.def}{2021-03-18}{}
    
  • Under XeLaTeX:

    (/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-xetex.def
    ! Missing \endcsname inserted.
    <to be read again> 
                       ^^M
    l.29   {l3backend-xetex.def}{2021-03-18}{}
    
  • Under LuaLaTeX:

    ...
    (/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-luatex.def
    ! Missing \endcsname inserted.
    <to be read again>
    

    l.29 {l3backend-luatex.def}{2021-03-18}{}

    Observe: no ^^M in the LuaLaTeX error message, unlike with the pdfLaTeX and XeLaTeX.

Aside: The Plain-TeX test document

\obeylines
abc
\bye

compiles fine under pdfTeX, XeTeX, and LauTeX.

Question: Is this a bug? A feature? Are there any known work-arounds? FWIW: I'm sure the test program compiles fine under MacTeX2020.

egreg
  • 1,121,712
Mico
  • 506,678
  • 7
    \obeylines is not really a preamble command. Best case scenario it will mess up reading the .aux file at \begin{document}, so if it worked before I'd say it was by accident – Phelype Oleinik Apr 14 '21 at 16:59
  • @PhelypeOleinik - Thanks for this. I wasn't aware of the fact one shouldn't use \obeylines in the preamble of a LaTeX document. – Mico Apr 14 '21 at 17:01
  • 3
    In this case the l3backend files could be changed to cope with that setting (adding two % at the end of the first two non-comment lines), and this MWE will work again, but I'd advise you to not trust that other code will be so tolerant. As a rule of thumb catcode changes (and in this case \endlinechar changes) should better be restricted to the document body (and preferrably enclosed in a group) – Phelype Oleinik Apr 14 '21 at 17:08
  • 4
    if you set it in the preamble then you are making the end of line in any package loaded or any files loaded at begin document active. If things work then that's by luck not planning – David Carlisle Apr 14 '21 at 17:08
  • 2
    In a similar context luatex doesn't show ^^M as the token to be read again, which seems a “feature”. – egreg Apr 14 '21 at 17:18
  • 1
    @egreg I think that's because luatex renders the actual ASCII 13 on the terminal, rather than the ^^M notation (which is not too helpful in this case) – Phelype Oleinik Apr 14 '21 at 17:23
  • 2
    @PhelypeOleinik On the other hand, if I assign \catcode`\^^M=15, the error message shows ^^M as the invalid character also with luatex. – egreg Apr 14 '21 at 17:33
  • 1
    AFAIK \obeylines is npt documented in the LaTeX manual or the companion or any other official documentation. So it isn't a LaTeX command. – Martin Schröder Apr 14 '21 at 21:10
  • 1
    @MartinSchröder - Thanks. \obeylines is defined in latex.ltx (in a way that's entirely analogous to its definition on p. 352 of the TeXbook); does that make it a LaTeX command? Anyway, as Phelype and others have already shown, the issue I was stumbling over was caused by me improperly running \obeylines in the preamble instead of in the body of document environment. – Mico Apr 14 '21 at 21:21

1 Answers1

7

Community Answer based on the Comments

The command \obeylines must be used after \begin{document} and not before \begin{document}.

Background

You may have several consecutive lines of input for which you want the output to appear line-for-line in the same way. One solution is to type \par at the end of each input line; but that’s somewhat of a nuisance, so plain TeX provides the abbreviation \obeylines, which causes each end-of-line in the input to be like \par. After you say \obeylines you will get one line of output per line of input, unless an input line ends with % or unless it is so long that it must be broken. For example, you probably want to use \obeylines if you are typesetting a poem. Be sure to enclose \obeylines in a group, unless you want this "poetry mode" to continue to the end of your document.

TeXBook at page 94

Correct

Version 1

\documentclass{article}

\begin{document} \obeylines % :)

Word Word

\end{document}

Version 2

\documentclass{article}

\begin{document}

% Alternative :) % https://latex.org/forum/viewtopic.php?t=12340 \begin{obeylines} Word Word \end{obeylines}

\end{document}

enter image description here

Not Correct

\documentclass{article}

\obeylines % :( \begin{document}

Word Word

\end{document}

<to be read again> 
                   \scan_stop: 
l.29   {l3backend-pdftex.def}{2021-07-12}{}

The control sequence marked <to be read again> should not appear between \csname and \endcsname.

enter image description here

Related