2

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...
\DTLloadrawdb{scores}{scores.csv}
\DTLdisplaydb{scores}

\end{document}
2

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 \$:

enter image description here

\documentclass{article}

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

\begin{document}

\DTLloadrawdb{scoresA}{scores.csv}
\DTLdisplaydb{scoresA}

\DTLrawmap{\%}{\$}% Map % to \$
\DTLloadrawdb{scoresB}{scores.csv}
\DTLdisplaydb{scoresB}

\end{document}

From the datatool user guide:

Naturally, the mappings must be set prior to loading the data with \DTLloadrawdb.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.