7

When I run the following code...

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tabular}{c}
\pgfmathsetmacro\foo{(2<3) && (3<4)}
\foo
\end{tabular}
\end{document}

I get

ERROR: Argument of \pgfmath@@onquick has an extra }.

If I use \pgfmathtruncatemacro, I get the same error. However:

  • If I delete the tabular environment, it works fine.

  • If I replace the operation with and((2<3),(3<4)), it works fine.

  • If I use \pgfmathparse...\pgfmathresult, it works fine.

Is there a fix for this? Clearly the problem is that tabular is somehow reading & as a row separator. (Currently, I use and instead of && in all my pgfmath code, for fear that my macros might be eventually put inside a tabular.)

2
  • 2
    You can hide it from tabular via extra braces {\pgfmathsetmacro\foo{((2<3) && (3<4))}\foo}
    – percusse
    Jun 20, 2013 at 5:32
  • @percusse Looks like the core of an answer to me
    – Joseph Wright
    Aug 19, 2013 at 10:39

1 Answer 1

4

\pgfmathsetmacro uses a \begingroup \endgroup group for its calculations which isn't enough to hide && from tabular, you could redefine it to use { instead but no promises that that doesn't break something else in pgf.

This works though:

\documentclass{article}
\usepackage{pgf}

\makeatletter
\def\pgfmathsetmacro#1#2{%
%\begingroup
{%
\pgfmathsetlength\pgfmath@x{#2}%
\edef#1{\pgfmath@tonumber{\pgfmath@x}}%
%\pgfmath@smuggleone{#1}\endgroup
\expandafter}\expandafter\def\expandafter#1\expandafter{#1}%
}
\makeatother

\begin{document}
\begin{tabular}{c}
\pgfmathsetmacro\foo{(2<3) && (3<4)}
\foo
\end{tabular}
\end{document}

You must log in to answer this question.

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