I've written a macro that scans its content for illegal characters and then changes them to something more appropriate. In the following example, the macro scans for _ and replaces them with \rule[-1pt]{0.75em}{1.0pt}.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\newcommand\aescandash[1]{%%
\let\ae@scan@dash@result\relax
\ae@scan@dash@parse#1_\@nil
\ae@scan@dash@result
}
\def\ae@add@to@result#1#2{%%
\ifx#1\relax
\def#1{#2}%%
\else
\expandafter\def\expandafter#1\expandafter{#1#2}%%
\fi}
\def\ae@scan@dash@parse#1_#2\@nil{%%
\def\ae@reevaluate{}%%
\expandafter\ifx\expandafter\relax\detokenize\expandafter{#2}\relax
\ae@add@to@result\ae@scan@dash@result{#1}%%
\else
\ae@add@to@result\ae@scan@dash@result{#1\rule[-1pt]{0.75em}{1.0pt}}%%
\def\ae@reevaluate{\ae@scan@dash@parse#2\@nil}%%
\fi
\ae@reevaluate
}
\makeatother
\begin{document}
\aescandash{this_is_a_dash_filled_sentence}
\end{document}
I would like to be able to apply such a pre-processor to the content of nodes in a TikZ picture:
\begin{tikzpicture}[%%
my node/.style={red,
preprocessor=\aescandash},
]
\foreach \myn [count=\myc from 1] in {this,that,another_text}
{
\node[my node] at (0,-\myc) {\myn};
}
\end{tikzpicture}
But there is no such preprocessor key. Ideally I would like the preprocessor to effectly pass to the node contents something along the lines of:
\expandafter\aescandash\expandafter{\myn}
In other words, the preprocessor would accomplish what the following code does:
\begin{tikzpicture}[%%
my node/.style={red},
]
\foreach \myn [count=\myc from 1] in {this,that,another_text}
{
\node[my node] at (0,-\myc) {\expandafter\aescandash\expandafter{\myn}};
}
\end{tikzpicture}



;-)– egreg Nov 22 '14 at 22:01