7

The following test document

\documentclass[english]{article}
\usepackage{babel}
\usepackage{ifxetex,ifluatex}
\ifluatex\else
  \ifxetex\else
    \usepackage[utf8]{inputenc}
  \fi
\fi
\usepackage{csquotes}
\MakeAutoQuote{»}{«}

\def\xxx{»Test automatic outer and »inner« quotes«}

\begin{document}

»Test automatic outer and »inner« quotes«

\xxx

\end{document}

compiled with pdflatex gives the expected result (two lines with correct quotings). With LuaLaTeX or XeLaTeX the second line is wrong (no quotings). Can anyone give me a hint? Thanks in advance.

5

This all comes down to tokenization and the fact that various changes take place during the \begin{document} line.

To work, csquotes needs to make any auto-quotes 'active' (category code 13) and to assign them the appropriate meaning. It does that during the \begin{document} line, so that any text read after this will work 'as expected'. However, tokens read before this happens is more complex as they will have their codes fixed when they are read. Thus \xxx is defined based on 'what is current in the preamble'.

With pdfTeX, you load inputenc which makes all code points >127 active at the point it is loaded. Thus \xxx is defined with » active (or rather with the two octets which make up this code points active). Thus there is no change in the codes during the \begin{document} line and everything works. However, for XeTeX and LuaTeX, » is a 'normal' character in the preamble (no special tricks are needed for it to work in general). So here there is a change during the start-of-document hook, with » being made active. This means that the definition inside \xxx is different from the outcome in the document body.

The solution is either

  • Only set up your text in the document body or
  • Make » and « active deliberately with \catcode`\»=\active\catcode`\«=\active

Messing with category codes is something of an expert area, so I'd favour the first solution!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.