1

The following code gives the error

! You can't use `macro parameter character #' in horizontal mode. \DTLifinlist ...4->\def \@dtl@doifinlist ##1,#1,## 2\end@dtl@doifinlist {\def... l.18 }

\documentclass{article}

\usepackage{datatool}

\begin{document}

\DTLnewdb{dtOne}%
\dtlexpandnewvalue
\DTLnewrow{dtOne}%
\DTLnewdbentry{dtOne}{Place}{Marché}%

\DTLforeach*{dtOne}%
{\Place=Place}%
{%
    \expandafter\DTLifinlist\expandafter{\Place}{Car,Man,Ferry}%
    {\Place: Found!\\}%
    {\Place: Not found!\\}%
}

\end{document}

If I %\dtlexpandnewvalue or if I change the db entry to \DTLnewdbentry{dtOne}{Place}{Marche}% ('é' changed in 'e'), the error goes away.

Is there a way to use \DTLifinlist with \dtlexpandnewvalue and accented characters?

0

2 Answers 2

0

You might protect the entry against expansion and then compare the entries as strings.

\documentclass{article}

\usepackage{datatool}

\newcommand{\DTLstringifinlist}[4]{%
  \begingroup\edef\x{\endgroup
    \noexpand\DTLifinlist{\detokenize\expandafter{#1}}{\detokenize{#2}}%
  }\x{#3}{#4}%
}
\newcommand{\DTLnewdbprotectedentry}[3]{%
  \DTLnewdbentry{#1}{#2}{\unexpanded{#3}}%
}

\begin{document}

\DTLnewdb{dtOne}
\dtlexpandnewvalue
\DTLnewrow{dtOne}
\DTLnewdbprotectedentry{dtOne}{Place}{Marché}

\DTLforeach*{dtOne}
  {\Place=Place}%
  {%
    \DTLstringifinlist{\Place}{Car,Man,Ferry}%
    {\Place: Found!}%
    {\Place: Not found!}%
  }

\DTLforeach*{dtOne}
  {\Place=Place}%
  {%
    \DTLstringifinlist{\Place}{Car,Man,Ferry,Marché}%
    {\Place: Found!}%
    {\Place: Not found!}%
  }

\DTLforeach{dtOne}{\Place=Place}{\Place}

\end{document}

enter image description here

Works with pdflatex, xelatex and lualatex.

2

Yes! Just use XeLaTeX to compile your code and no errors will be generated!

Alternatively, if you insist on using pdfLaTeX, you can replace Marché with March\'e, and no errors will be generated.


I shall quote from the datatool documentation:

Page 84: As from version 2.24, the predefined handlers now have limited support for UTF-8 characters. This is still experimental.

and

Page 85: With regular (pdf)LaTeX (as opposed to XeLaTeX) each UTF-8 character is actually treated as two tokens that represent the first and second octet of the UTF-8 character. This means that it’s not possible for TeX to obtain a character code using the usual backtick method…

3
  • 2
    LuaLatex would also be an option.
    – Daniel
    Aug 17, 2018 at 5:47
  • Indeed, March\'e solves the problem. So, UTF-8 seems to dislike \DTLifinlist only ... as I have no problem with the other Datatool commands. Rem: the note of page 84 is about the sorting handlers. Aug 17, 2018 at 7:40
  • @JosephMarie If you look at the example of \DTLnewdbentry on page 46 of the documentation, you will find that the author intentionally used Z\"oe instead of Zöe. My point is that UTF-8 is not very-well supported (it could be a bug of the package). Aug 17, 2018 at 12:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .