I need to print named xtics in extended mode. The problem is that the names stored in "selected_indices" contain underscores. To print them as underscores in extended mode, the underscores must be preceded by three backslashes. How can I insert these three backslashes automatically when I add the xtics to a plot?
original:
n_indices = words(selected_indices)
selected_indices = "A_a B_b"
print selected_indices
wanted:
selected_indices = "A\\\_a B\\\_b"
print selected_indices
set xtics ( '' 1 )
set for [i=1:n_indices] xtics add ( sprintf("{/:Bold %s}", word( selected_indices, i ) ) i )
The first thing which comes to my mind is simply to replace the
_by\_. Mind the difference with single and double quotes, either"\\\_"or'\_'.In the following script, a function is defined to replace the first underscore (
_) in a string by backslash + underscore (\_). With this, you can "un"enhance the underscore for subscript, but still use^for subscript. Maybe there are better solutions.Script:
Result:
Addition:
In case you have multiple underscores in your string, you can replace them all by the following function:
Result: