1

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|...|?

1

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*}

\DTLloaddb{testdatabase}{test.csv}


\makeatletter
\newcommand\myDTLloaddbwrapper[2]{%
  \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. ) 
  \DTLloaddb{#1}{#2}%
  \endgroup
}%
\makeatother

\myDTLloaddbwrapper{testdatabaseB}{test.csv}

\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}

enter image description here

(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.

More information at

https://www.dickimaw-books.com/latex/admin/html/loadcsv.shtml

\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

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.