2

The following MWE yields two different subscripts for pgfkeys that use .estore and .store and seems like the one with the .store produce the correct subscript.

What is the reason of this difference? Is it a conflict with amsmath?

\documentclass[]{standalone}
\usepackage{amsmath}
\usepackage{tikz}

\pgfkeys{/sdof/.is family, /sdof,
    disp text estore/.estore in = \disptextestore,
    disp text store/.store in = \disptextstore,}

\newcommand{\sdof}[1][]{\pgfkeys{/sdof, #1}
    \node at (0,0) {\disptextestore};
    \node at (2,0) {\disptextstore};
}

\begin{document}

\begin{tikzpicture}
    \sdof[disp text estore=Estore: $x_{\text{s}}$,
          disp text store=Store: $x_{\text{s}}$,]
    \node at (4, 0) {Typical: $x_{\text{s}}$};
\end{tikzpicture}

\end{document}

enter image description here

0

1 Answer 1

4

The problem you are facing with is not related to pgfkeys, but comes from the combination of \edef and \protect.

Let me consider the following MWE.

\documentclass{article}
\usepackage{amstext}
\def\foo{
  \displaystyle \text{D},
  \textstyle \text{T},
  \scriptstyle \text{S},
  \scriptscriptstyle \text{SS},
}
\edef\bar{\foo}
\begin{document}
$\foo \quad \bar$
\end{document}

The result is like this and you will find that \texts do not respect the preceding \...styles in \bar.

non-working \text

This is because of the fact that the \text command is defined in amstext.sty as

\DeclareRobustCommand{\text}{%
  \ifmmode\expandafter\text@\else\expandafter\mbox\fi}

This means \text is a self-\protected command and thus safe in most contexts, but \protect won't survive inside an \edef because \edef is a TeX primitive.

Robust commands inside an \edef sometime work. For instance,

\documentclass{article}
\usepackage{amstext}
\makeatletter
\def\foo{
  \displaystyle \text{D},
  \textstyle \text{T},
  \scriptstyle \text{S},
  \scriptscriptstyle \text{SS},
}
\let\@@protect\protect
\let\protect\@unexpandable@protect
\edef\bar{\foo}
\let\protect\@@protect
\makeatother
\begin{document}
$\foo \quad \bar$
\end{document}

will give the expected result (and this is what \protected@edef and \protectded@xdef do). However, this depends on the situation.

protected

You can also benefit from the e-TeX's \protected (possibly using the etoolbox package):

\documentclass{article}
\usepackage{amstext}
\usepackage{etoolbox}
\makeatletter
\robustify{\text}  % this utilizes the e-TeX's low-level feature instead of LaTeX's high-level protection.
\def\foo{
  \displaystyle \text{D},
  \textstyle \text{T},
  \scriptstyle \text{S},
  \scriptscriptstyle \text{SS},
}
\edef\bar{\foo}
\makeatother
\begin{document}
$\foo \quad \bar$
\end{document}

That being said, my recommendation is to avoid using the .estore in handler unless absolutely needed.

1
  • Thanks for the explanation. Whenever I have an isssue that I cannot identify the reason of, it ends up at the back alleys of TeX!
    – berkus
    Dec 1, 2017 at 21:15

You must log in to answer this question.

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