2

When reading a temporary file, I get an error when switching to french (comment/uncomment documentclass):

Runaway argument?
testcolor;testtext \\\textbf {\ChangesIncolor \ -- \ChangesIntext }\fi \ETC.
! Paragraph ended before \changeschopline was complete.

I am assuming, french language uses the ; differently, thus the error, but I am not sure and I don't know how to fix the problem.

Thanks for your knowledge.

MWE:

\begin{filecontents*}{\jobname.soc}
testcolor;testtext
\end{filecontents*}

% \documentclass[english]{article}
\documentclass[french]{article} % error reading file

\usepackage{babel}

\def\changeschopline#1;#2 \\{%
    \def\ChangesIncolor{#1}%
    \def\ChangesIntext{#2}%
}

\newcommand{\listofchanges}{
    \newread\ChangesInFile%
    \openin\ChangesInFile = \jobname.soc%
    \loop\unless\ifeof\ChangesInFile%
        \read\ChangesInFile to \ChangesLine%
        \ifeof\ChangesInFile\else%
            \expandafter\changeschopline\ChangesLine\\%
            \textbf{\ChangesIncolor\ -- \ChangesIntext}%
        \fi%
    \repeat
    \closein\ChangesInFile%
}

\begin{document}

    \listofchanges

\end{document}

Disclaimer: I am using this for the changes package, see issue and test files here:

2
  • 1
    You can try disabling babel shorthands; e.g. tex.stackexchange.com/a/106325
    – imnothere
    Commented Jul 5, 2021 at 2:44
  • 2
    Your file compiles fine with LuaLaTeX (and XeLaTeX). WIth pdfLaTeX, the semi-colon is active in French, that's the origin of the clash. WIth pdfLaTeX, you could use another delimiter (like -) instead of the active ; Note that : ! and ? are also active in French with pdfLaTeX. Commented Jul 5, 2021 at 8:22

1 Answer 1

0

Thanks for the helpful comments, my solution is to switch off the shorthand character ; before reading the file and switching it on afterwards.

So far there are no side effects and looking in the babel documentation: nearly every character I considered as a substitute is a shorthand character in at least one language :D

\begin{filecontents*}{\jobname.soc}
testcolor;testtext
\end{filecontents*}

\documentclass[french]{article}

\usepackage{babel}

\def\changeschopline#1;#2 \\{%
    \def\ChangesIncolor{#1}%
    \def\ChangesIntext{#2}%
}

\newcommand{\listofchanges}{
    \ifbabelshorthand{;}{\shorthandoff{;}}{}
    \newread\ChangesInFile%
    \openin\ChangesInFile = \jobname.soc%
    \loop\unless\ifeof\ChangesInFile%
        \read\ChangesInFile to \ChangesLine%
        \ifeof\ChangesInFile\else%
            \expandafter\changeschopline\ChangesLine\\%
            \textbf{\ChangesIncolor\ -- \ChangesIntext}%
        \fi%
    \repeat
    \closein\ChangesInFile%
    \ifbabelshorthand{;}{\shorthandon{;}}{}
}

\begin{document}

    Qu'est-ce que c'est ? C'est; c'est: c'est! ...

    \listofchanges

    Qu'est-ce que c'est ? C'est; c'est: c'est! ...

\end{document}

You must log in to answer this question.

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