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.

9
  • 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 Commented Apr 14, 2021 at 16:59
  • 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) Commented Apr 14, 2021 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 Commented Apr 14, 2021 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
    Commented Apr 14, 2021 at 17:18
  • 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
    Commented Apr 14, 2021 at 17:33

1 Answer 1

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

1
  • it does not seem to work in beamer Commented Feb 16, 2023 at 14:10

You must log in to answer this question.

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