2

I have used \footnotesize to scale labels before and it has produced the desired results. But am having problems when I pass this as part of the label to a macro. The following MWE compiles but not if I comment out the line that redefines \footnotesize.

If needed, further details of \ShowIntersection can be found in Intersections in PGFplots and GetListMember can be found in Macro to access a specific member of a list

\documentclass{standalone}

\usepackage{xstring}
\usepackage{pgfplots}
\usetikzlibrary{intersections}

\pgfkeys{/pgfplots/Linear Axis Style/.style={
        clip=true,
        minor tick num=0,
        axis y line=center,
        axis x line=middle, 
        x axis line style={name path global=XAxisLine},
        y axis line style={name path global=YAxisLine}
    }
}

\begin{document}

\newcommand*\GetListMember[2]{\StrBetween[#2,\number\numexpr#2+1]{,#1,},,}%

\newcommand*{\ShowIntersection}[3]{
\fill 
    [name intersections={of=#1 and #2, name=i, total=\t}] 
    [red, opacity=1, every node/.style={black, opacity=1}] 
    \foreach \s in {1,...,\t}{(i-\s) circle (2pt)
        node [above left, blue] {\GetListMember{#3}{\s}}};
}

\begin{tikzpicture}
\begin{axis}[Linear Axis Style,
    xmin=-1.5, xmax=1.51,% Need asymmetry here due to bug in PGFplots
    ymin=-1, ymax=3,
    ]

\addplot[name path global=a, mark=none, domain=-2.5:2.5, thick] ({x},{x*x-0.5});%

\def\footnotesize{}% Why can I not comment this out?
\ShowIntersection{a}{XAxisLine}{{\footnotesize{$X_1$}},{$(A,B)$}}
\ShowIntersection{a}{YAxisLine}{{\footnotesize{$Y$}}} 

\end{axis} 
\end{tikzpicture}
\end{document}
Peter Grill
  • 223,288

1 Answers1

3

To fix this use either the \normalexpandarg setting of xstring (e.g. in the preamble) or write \noexpand\noexpand\noexpand\footnotesize instead of just \footnotsize.

The issue is the xstring operation. A MWE would be:

\documentclass{article}
\usepackage{xstring}
\begin{document}
% your macro:
\newcommand*\GetListMember[2]{\StrBetween[#2,\number\numexpr#2+1\relax]{,#1,},,}%
\GetListMember{\footnotesize A}{1}
% or just:
\StrBetween[1,2]{,\footnotesize,}{,}{,}
\end{document}

The definition of the \footnotesize macro starts with \@setfontsize \footnotesize ..., where \@setfontsize includes \let \@currsize #1, i.e. each font size macro stores itself as \@currsize (presumingly to be able to be restored later). Now \StrBetween expands the string twice. Apparently once when the comma separated values are read in and then again for the selected substring. Therefore you need to use \noexpand twice plus one, makes three times (to not expand the second \noexpand).

The \normalexpandarg (alternatively \expandarg) macro of xstring defines some internal macro in a way that these expansions are not done (\def instead of \edef).

Martin Scharrer
  • 262,582