这个 TeX 错误让我快要抓狂了,但是我找不到任何有效的方法来解决这个问题。下面是一个导致问题的小例子,我在我的代码中确实需要它:
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{datatool}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{filecontents}
% \begin{filecontents*}{emaildb.csv}
% FirstName,Surname,Email1,Email2,Reg Num
% Mary,Jones,[email protected],[email protected],0
% Adam,Smith,[email protected],,12345
% \end{filecontents*}
\begin{filecontents*}{abc.csv}
Zeit/s,AMES\_13,AMES\_14,AMES\_15,AMES\_16
"3,0",000,"8,760V","0,000","0,216mA"
"6,0",000,"13,120V","0,000","0,169mA"
"9,0",000,"16,550V","0,000","0,132mA"
"12,0",000,"19,660V","0,000","0,103mA"
"15,0",000,"21,730V","0,000","0,081mA"
"18,0",000,"23,580V","0,000","0,066mA"
"21,0",000,"24,850V","0,000","0,052mA"
"24,0",000,"25,980V","0,000","0,041mA"
"27,0",000,"26,740V","0,000","0,033mA"
"30,0",000,"27,420V","0,000","0,026mA",
"33,0",000,"27,890V","0,000","0,021mA"
"36,0",000,"28,300V","0,000","0,017mA"
"39,0",000,"28,590V","0,000","0,014mA"
"42,0",000,"28,820V","0,000","0,012mA"
"45,0",000,"29,020V","0,000","0,010mA"
"48,0",000,"29,150V","0,000","0,009mA"
"51,0",000,"29,280V","0,000","0,008mA"
"54,0",000,"29,360V","0,000","0,007mA"
"57,0",000,"29,430V","0,000","0,006mA"
"60,0",000,"29,490V","0,000","0,006mA"
"63,0",000,"29,520V","0,000","0,005mA"
"66,0",000,"29,560V","0,000","0,005mA"
"69,0",000,"29,580V","0,000","0,004mA"
"72,0",000,"29,610V","0,000","0,004mA"
"75,0",000,"29,630V","0,000","0,004mA"
\end{filecontents*}
\begin{document}
\DTLloaddb{ddb}{abc.csv}
\end{document}
但是如果我注释filecontents
并emaildb.csv
更改,\DTLloaddb{ddb}{emaildb.csv}
则不会出现错误。这意味着,abc.cvs
但是,我也重新输入了它,确保其中没有奇怪的不可见字符,但它仍然显示Missing \endscname inserted
:(
答案1
此处的问题是数据库标题中活动字符的使用。
使用 加载数据库时\DTLloaddb
,datatool
建议考虑使用密钥
autokeys
这是一个布尔选项,无论文件是否有标题行,它都会自动为所有列分配默认键 [..]。如果为真,则此选项将覆盖键选项。如果您的标题行包含许多包含活动字符的字段,但您只想使用类似 的命令,则可能需要使用此选项。
\DTLdisplaydb
(在这种情况下,您可能需要考虑使用\DTLloadrawdb
来加载数据。)
第二个建议是考虑使用以下方法加载数据库
\DTLloadrawdb
这与 相同,
\DTLloaddb
只是它将十个特殊字符中的九个映射到产生该符号的命令上。唯一保持活动状态的字符是反斜杠字符,因此您仍需要检查文件中是否存在反斜杠字符。使用的映射是 [..]% -> \% $ -> \$ & -> \& # -> \# _ -> \_ { -> \{ } -> \} ~ -> \textasciitilde ^ -> \textasciicircum
...或者通过定义您自己的映射\DTLrawmap{<string>}{<replacement>}
。
建议避免在数据库中使用活动字符(除非真的keys
需要)和/或使用和键的组合headers
:
keys
这是要使用的键的逗号分隔列表,其中键的列出顺序与列的顺序相同。如果文件有标题,这些键将覆盖标题行中给出的值。如果文件没有标题行,并且 中没有提供任何键
<options>
,则键将由 给出\dtldefaultkey<n>
,其中<n>
是\dtldefaultkey
列号,\dtldefaultkey
默认为“Column”。请注意,键列表必须用括号分隔,因为它们包含逗号。
headers
这是以逗号分隔的标题列表。如果未提供,则标题将与标题行中给出的标题相同,如果没有标题行,则标题将与键相同。请注意,标题列表必须用括号分隔,因为它们包含逗号。
例如,使用
\begin{filecontents*}{abc.csv}
first,second,third,fourth,fifth
"3,0",000,"8,760V","0,000","0,216mA"
..
然后使用加载
\DTLloaddb[
keys = {first,second,third,fourth,fifth},
headers = {Zeit/s,AMES\_13,AMES\_14,AMES\_15,AMES\_16}
]{ddb}{abc.csv}
答案2
datatool
尝试使用第一行中的项目来创建命令名称,但是\_
在允许这样做的构造中这是不合法的。
最好的办法是避免使用特殊字符,但好消息是,不转义也是_
可行的。
\begin{filecontents*}{abc.csv}
Zeit/s,AMES_13,AMES_14,AMES_15,AMES_16
"3,0",000,"8,760V","0,000","0,216mA"
"6,0",000,"13,120V","0,000","0,169mA"
这可能如果您想打印这些标题,稍后会产生问题。如果您发现此类问题,请更新您的问题。