0

I cannot figure out what I am doing wrong in this basic example. I want to have a function inside my expl3 code draw a simple picture with tikz, but I get an error Package pgf Error: No shape named 0:0 is known.

MWE

\documentclass{extbook}

\usepackage{tikz} \usetikzlibrary{arrows,automata,positioning,calc}

% my command to draw an orange rectangle with tikz \newcommand{\drawmyshape}{ \tikz[font=\normalsize]{ \draw[color=orange!50, fill=orange] (0:0) -- ++(\linewidth,0) -- ++(0,-2em) -- (0,-2em) -- (0,0); }%%%%% }%%%%%

\usepackage{xparse}%allows the NewDocumentCommand

\ExplSyntaxOn

%Why does the tikz code inside the expl3syntax break it? I need to be able to call this here. \NewDocumentCommand{\drawmyshapeagain}{}{ \tikz[font=\normalsize]{ \draw[color=orange!50, fill=orange] (0:0) -- ++(\linewidth,0) -- ++(0,-2em) -- (0,-2em) -- (0,0); }%%%%% }%%%%%

\ExplSyntaxOff

\begin{document}

\drawmyshape

\drawmyshapeagain

\end{document}

Bob
  • 1,270
  • 9
  • 14
  • 1
    See https://tex.stackexchange.com/questions/197083/workaround-how-to-use-expl3-functionality-in-tikz I guess. – Torbjørn T. Jan 19 '21 at 21:23
  • Thank you guys for the pointer, I was having a hard time searching for something so simple! – Bob Jan 20 '21 at 00:14

1 Answers1

5

In expl3 the colon is a letter, and this breaks the (0:0) in your code. You don't use expl3 commands in your example so the easiest is to simply remove the \ExplSyntaxOn command, but if you need it for something else you can use (in this case, this doesn't work always) \c_colon_str :

\documentclass{extbook}

\usepackage{tikz} \usetikzlibrary{arrows,automata,positioning,calc}

% my command to draw an orange rectangle with tikz \newcommand{\drawmyshape}{ \tikz[font=\normalsize]{ \draw[color=orange!50, fill=orange] (0:0) -- ++(\linewidth,0) -- ++(0,-2em) -- (0,-2em) -- (0,0); }%%%%% }%%%%%

\usepackage{xparse}%allows the NewDocumentCommand

\ExplSyntaxOn

%Why does the tikz code inside the expl3syntax break it? I need to be able to call this here. \NewDocumentCommand{\drawmyshapeagain}{}{ \tikz[font=\normalsize]{ \draw[color=orange!50, fill=orange] (0\c_colon_str0) -- ++(\linewidth,0) -- ++(0,-2em) -- (0,-2em) -- (0,0); }%%%%% }%%%%%

\ExplSyntaxOff

\begin{document}

\drawmyshape

\drawmyshapeagain

\end{document}

Ulrike Fischer
  • 327,261