TransWikia.com

Looking up strings by an index

TeX - LaTeX Asked on June 21, 2021

I’m using pgfplotsinvokeforeach{0,1,2} {...} and would like to somehow dispatch on #1 to get one of three strings:

  • $s_A$ if #1 == 0
  • $s_B$ if #1 == 1
  • $s_C$ if #1 == 2

Is there an easy way to do this? I’ve tried using xstring’s StrMid but it bombs and complains about let doing something wrong.

2 Answers

You can try this solution based on LaTeX3. Not sure if it works with pgfplotsinvokeforeach in your code though.

documentclass{article}
usepackage{expl3}

ExplSyntaxOn
newcommand{intcase}[1]{
  int_case:nn {#1} {
    {1} {$sc_math_subscript_token A$}
    {2} {$sc_math_subscript_token B$}
    {3} {$sc_math_subscript_token C$}
  }
}
ExplSyntaxOff

begin{document}
intcase{1}intcase{2}intcase{3}
end{document}

Answered by Alan Xiang on June 21, 2021

documentclass{article}
usepackage{pgfplotstable}
pgfplotsset{compat=1.16}
newcounter{tmpcnt}
begin{document}
pgfplotsinvokeforeach{0,1,2}{%
  setcounter{tmpcnt}{numexpr1+#1}$s_{Alph{tmpcnt}}$}
end{document}

enter image description here

Answered by Steven B. Segletes on June 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP