During pdfLaTeX processing, I'm writing a string of key-value pairs to an external file. Sometimes the value will contain \#
and I want only the #
to be written to the file.
Here is my code which works fine as long as I just need to write plain text.
Assume that every key is defined as \@empty
by default; it is only written to the file
if it has a value other than \@empty
.
e.g. \def\objects{\@empty}\def\mystring{\@empty}
\newcommand{\setoptions}{%
\global\edef\finaloption{}
\getkeyval{objects}\getkeyval{mystring}
}
\newcommand{\getkeyval}[1]{%
\def\tmpkey{#1}
\edef\tmpval{\csname #1\endcsname}
\ifx\@empty\tmpval
\else
\edef\finaloption{\finaloption,\tmpkey=\tmpval}
\fi
}
Then later this line writes the key-value pairs to the external file:
\setoptions
\immediate\write\mypgm{\finaloption}
I suppose I need to loop through \tmpval
checking for \char23
?
Is that a step in the right direction?
Edit: An example of the LaTeX input:
\mytag[mystring=val, objects=App\#1 App\#2,caption={my title}]{myarg}
I parse and retrieve the key-value pairs and I want to write this line to the external file:
mystring=val, objects=App#1 App#2
\char23
and#
are not always the same. While both will typeset the same character, the first doesn't expand to the latter. Also do you really have\#
or#
? In the case of\#
, just redefine that macro (!) to produce a verbatim#
.