2

I want to use a TikZ environment inside an \ExplSyntaxOn... \ExplSyntaxOff block.

\documentclass{article}


\usepackage[utf8]{inputenc}

\usepackage{xparse}

\usepackage{tikz}
\usetikzlibrary{positioning}


\ExplSyntaxOn

\NewDocumentCommand{\maketikz}{ O{,} m }{%
\begin{tikzpicture}[%
    padding/.append style={inner sep=2px},%
    node distance=2pt
]
    \node[draw] {#2};
\end{tikzpicture}
}

\ExplSyntaxOff


\begin{document}
    
\maketikz[;]{Yes}
    
\end{document}

During the build process I get errors for the TikZ styles: I do not know the key '/tikz/padding/.appendstyle', to which you passed 'innersep=2px... and I do not know the key '/tikz/nodedistance', to which you passed '2pt'....

Without \ExplSyntaxOn it builds without any errors.

\documentclass{article}


\usepackage[utf8]{inputenc}

\usepackage{xparse}

\usepackage{tikz}
\usetikzlibrary{positioning}


\newcommand{\maketikz}[2][,]{
\begin{tikzpicture}[%
    padding/.append style={inner sep=2px},%
    node distance=2pt
]
    \node[draw] {#2};
\end{tikzpicture}
}


\begin{document}
    
\maketikz[;]{Yes}
    
\end{document}

Where is my mistake?

5
  • 7
    in expl3 context spaces are ignored, and you must use ~, e.g. padding/.append~style={inner~sep=2px} Aug 3 at 9:47
  • Don't use px. Very likely it is not what you might think it to be.
    – egreg
    Aug 3 at 9:52
  • @UlrikeFischer ooohhh, this should have been so obvious, thanks alot!
    – Mountain
    Aug 3 at 13:24
  • @egreg it was just a typo of CSS muscle memory, thanks
    – Mountain
    Aug 3 at 13:24
  • @UlrikeFischer Want to make that an answer?
    – schtandard
    yesterday

0

Your Answer

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

Browse other questions tagged or ask your own question.