# How to map special characters in CSV to something else when processing via datatool

The datatool user guide mentions that certain special characters are automatically mapped to the typesetting equivalent when loading a database in raw mode (via \DTLloadrawdb). If you want to change the mapping, use (for example)

\DTLrawmap{£}{\pounds}


However, how do I map active characters like %, $, &, _, ... to something else? The following minimal example fails to map % to something other than \% (for obvious reasons; % is an active comment character): \documentclass{article} \usepackage{filecontents,datatool} \begin{filecontents*}{scores.csv} Name, Score Alpha, 80.2% Beta, 91.3% Average, 85.75% \end{filecontents*} \begin{document} \DTLrawmap{%}{\$}% <--- this fails...
\DTLdisplaydb{scores}

\end{document}


Use the escaped version of the character in the <string> part of \DTLrawmap{<string>}{<replacement>}. For example,

\DTLrawmap{\%}{\$}  would replace % in the source CSV with \$:

\documentclass{article}

\usepackage{filecontents,datatool}
\begin{filecontents*}{scores.csv}
Name, Score
Alpha, 80.2%
Beta, 91.3%
Average, 85.75%
\end{filecontents*}

\begin{document}

\DTLrawmap{\%}{\$}% Map % to \$

From the datatool user guide:
Naturally, the mappings must be set prior to loading the data with \DTLloadrawdb.