2

When I use expl3 with tikz errors are raised (pdflatex). My complete code is

\documentclass{article}
\usepackage{tikz}
\ExplSyntaxOn
\begin{document}
\begin{tikzpicture}
\draw(0,0)--(3,3);
\end{tikzpicture}
\end{document}

You can see the effect here. I notice that using xelatex the code in the link compiles correctly. Nevertheless it sometimes still functions badly.

What is the method to have them work better together?

youthdoo
  • 861

1 Answers1

5

Doing \begin{document} under the scope of \ExplSyntaxOn is a very bad idea, sorry.

Several packages delay loading configuration files at begin document and inputting a file under the \ExplSyntaxOn regime is, to say the least, risky: spaces and endlines are ignored and if a file does

\mycountera=100
\ifnum\mycounterb=\mycountera 10\else 0\fi

(made up code to show one of the possible issues) you'd end with \mycountera holding the value 10010 or 1000, depending on the current value of \mycounterb. The given code is valid and would set \mycountera to 100 when spaces aren't ignored, then print 10 or 0. But when spaces are ignored, the \ifnum is expanded prior to TeX having determined the value passed to \mycountera.

Think to \ExplSyntaxOn as bringing an aircraft to the hangar for installation of new equipment. You want to end the installation before pulling the aircraft on the runway for take-off, don't you?

When you're under \ExplSyntaxOn regime, never do typesetting. Well, sometimes

\ExplSyntaxOn<expl3 code>\ExplSyntaxOff

might be appealing inside document. Avoid it and define prior to \begin{document} a user level command doing the business: install the equipment first, then take-off.

David's answer to Checking whether an item of a string is space is a case: his usage of \ExplSyntaxOn inside document was just by way of example, but not aimed to be what you'd do in a real document.

egreg
  • 1,121,712