# datatool - How can you load database from .csv-file with values tokenized with same catcode-settings as are used by \verb|...|?

I plan to use the package datatool for loading a .csv-file as database:

\DTLloaddb[<options>]{<db name>}{<filename>}


How to achieve tokenizing values of that database under the same catcode-settings as are used by \verb|...|?

I think it is sufficient to switch to the desired catcode-régime right before calling \DTLloaddb.
You may need to call \DTLsetdelimiter and/or \DTLsetseparator for adjusting delimiter and separator to the desired catcode-régime, too.

!!! But I don't know whether such catcode-changes affect the sorting-algorithms or whatsoever other functionality of the datatool-package. !!!

\documentclass{article}
\usepackage{datatool}

\begin{filecontents*}{test.csv}
ColumnA,ColumnB
\TeX,\LaTeX
\end{filecontents*}

\makeatletter
\begingroup
% Let's switch to verbatim-catcode-régime:
\let\do\@makeother  \dospecials
% ( You may need to call \DTLsetdelimiter and/or \DTLsetseparator with an argument
%   that also got tokenized under verbatim-catcode-régime.
%   I don't do it here because category-codes of default-delimiter " and
%   default-separator , are not affected when switching to verbatim-catcode-régime. )
\endgroup
}%
\makeatother

\begin{document}

\DTLforeach{testdatabase}{\ColA=ColumnA, \ColB=ColumnB}{%
\par\noindent\ColA{} and \ColB.
}%

\DTLforeach{testdatabaseB}{\ColA=ColumnA, \ColB=ColumnB}{%
\par\noindent{\csname verbatim@font\endcsname\ColA{} and \ColB}.
}%

\end{document}


(The possibility of specifying the desired catcode-régime for each column (and probably post-processing-routines to be applied to the values of a column) when loading a .csv-file via \DTLloaddb would be extremely nice.)

In case you just wish to disable some of the special characters, the command \DTLloadrawdb might be the right tool.

\DTLloadrawdb[⟨options⟩]{⟨db-name⟩}{⟨filename⟩}

This is like \DTLloaddb except that it performs a substitution on nine of the ten special characters. (The backslash always retains its special state.) The mappings are listed in Table 2.1.

Table 2.1: Special character mappings used by \DTLloadrawdb

Character Mapping

%          \%
$\$
&          \&
#          \#
_          \_
{          \{
}          \}
~          \textasciitilde
^          \textasciicircum