Is there a way to replace special characters in a string with \StrSubstitute
? For example, how can I make something like \StrSubstitute{#1}{&}{&\bfseries }
work?
I am asking because I was trying to define a macro that boldens a row of a table along the lines of
\newcommand{\thead}[1]{\bfseries \StrSubstitute{#1}{&}{&\bfseries }}
so that you could write in a document
\usepackage{booktabs, xstring}
\newcommand{\thead}[1]{\bfseries \StrSubstitute{#1}{&}{&\bfseries }\\ \toprule}
\begin{document}
\begin{tabular}{cc}\toprule
\thead{Item & price}\\ \toprule
foo & 1\\
bar & 2\\ \bottomrule
\end{tabular}
\end{document}
I noticed that there is a solution for that specific problem here: Make first row of table all bold, by replacing cc
by $c^c
. I was still wondering about how to replace special characters with the xstring package in its own right, maybe for other uses in the future. Also, a macro that wouldn't require changing cc
to $c^c
might be preferred by some.