LaTeX 与 Datatool 配合使用效果不佳

LaTeX 与 Datatool 配合使用效果不佳

datatool我使用(命名)在 LaTeX 中创建了问题数据库,nayi17n-ii如下所示

\DTLnewdb{CS2}
\long\def\newproblem#1#2#3#4#5#6#7#8#9{%
  \DTLnewrow{CS2}%
  \DTLnewdbentry{CS2}{seq}{#1}%
  \DTLnewdbentry{CS2}{yr}{#2}%
  \DTLnewdbentry{CS2}{sub}{#3}%
  \DTLnewdbentry{CS2}{top}{#4}%
 \DTLnewdbentry{CS2}{mar}{#5}%
\DTLnewdbentry{CS2}{qus}{#6}%
\DTLnewdbentry{CS2}{url}{#7}%
\DTLnewdbentry{CS2}{exp}{#8}%
\DTLnewdbentry{CS2}{ans}{#9}%
}

\newproblem{1}{2017-ii}{DE}{number}{1}{{The representation of the value of a 16-bit unsigned integer $X$ in hexadecimal number system is BCA9. The representation of the value of $X$ in octal number system is}\\
(A)571244\\
(B)736251\\
(C)571247\\
(D)136251\\
\hspace*{\fill} GATE 2017-II,1 MARK\\}{\url{http://gatefreaks.com/index.php?qa=9446&qa_1=de-gate-2017-2-1}}{$( BCA9)_{16}=(1011 \ 1100 \ 1010 \ 1001)_2$\\
   =$(001 \ 011 \ 110 \ 010 \ 101 \ 001)_2 = (136251)_8$.}{Ans:d}


\newproblem{2}{2017-ii}{C}{fun}{1}{{Match the following:}\\
\begin{tabular}{|p{0.05in}|p{0.85in}|p{0.05in}|p{1.5in}|p{0.15in}|p{1.0in}|p{1.0in}}
  \hline
P.& static char var;    &i.& Sequence of memory locations to store addresses\\ \hline
Q.& m=malloc(10); m=NULL;&  ii.& A variable located in data section of memory\\ \hline
R.& char *ptr[10];  &iii.& Request to allocate a CPU register to store data\\ \hline
S.& register int varl;  &iv.& A lost memory which cannot be freed\\
  \hline
\end{tabular}\\
(A)P-ii; Q-iv; R-i; S-iii\\
(B)P-ii; Q-i; R-iv; S-iii\\
(C)P-ii; Q-iv; R-iii; S-i\\
(D)P-iii; Q-iv; R-i; S-ii\\
\hspace*{\fill} GATE 2017-II,1 MARK\\}{\url{http://gatefreaks.com/index.php?qa=9447&qa_1=c-gate-2017-2-2}}{static char var = A: variable located in data section of memory.\\
m= malloc(10); m= null : A lost memory which cannot be freed because memory location m is not being freed.\\
Char *Ptr[10]: Sequence of  memory locations to store addresses, it can store 10 addresses.\\
register int var1 :register storage class is used so request to alloacte a CPU register to store data\\
Option a is correct.\\
}{Ans:a}

我正在从另一个文件编译该数据库,其内容如下:

\documentclass[10pt,twocolumn]{book}
\usepackage{layouts}
\usepackage{longdata}
\usepackage{url}
\usepackage{bm}
\usepackage{fancyvrb}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{mathtools}
\usepackage{scalerel}
\usepackage{stackengine}
\input{nayi17n-ii.tex}
\begin{document}

\begin{enumerate}
\DTLforeach[\DTLisclosedbetween{\seq}{1}{100}]%
           {CS2}%
           {\seq=seq,\yr=yr,\sub=sub, \top=top, \mar=mar,\qus=qus, \ans=ans}%
          {\DTLifstringeq{\yr}{2017-ii} { \item \qus }{}}
\end{enumerate}\end{document}

它运行正常,但我重新安装protext并尝试再次编译这些文件,但现在它无法正常工作并显示错误。与之相关的任何文件都datatool无法正常工作并显示相同的错误。

......
"C:\Program Files\MiKTeX 2.9\tex\latex\ltxmisc\varwidth.sty"))
("C:\Program Files\MiKTeX 2.9\tex\latex\url\url.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\tools\bm.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\fancyvrb\fancyvrb.sty"
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix 
<2008/02/07> (tvz))
("C:\Program Files\MiKTeX 2.9\tex\latex\fancyhdr\fancyhdr.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\tools\multicol.sty"

Package multicol Warning: May not work with the twocolumn option on input line 
134.
) ("C:\Program Files\MiKTeX 2.9\tex\latex\draftwatermark\draftwatermark.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\everypage\everypage.sty")) (ocgx.sty
(ocg-p.sty ("C:\Program Files\MiKTeX 2.9\tex\latex\eso-pic\eso-pic.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\atbegshi.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\infwarerr.sty")
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ltxcmds.sty")))))
("C:\Program Files\MiKTeX 2.9\tex\latex\titlesec\titlesec.sty") (scalerel.sty)
(stackengine.sty (listofitems.sty (listofitems.tex))) (nayi17n-ii.tex
! Undefined control sequence.
<argument> ...l@datatype }\fi \toks@gput@right@cx 
                                                  {dtlkeys@CS2}{\noexpand \d...
l.40 }{Ans:a}

? 

答案1

您使用的包裹应该做什么longdata

加载包datatool并将两个给定的代码组合成一个 MWE 后,我可以进行无错误编译......

查看 MWE

\documentclass[10pt,twocolumn]{book}
\usepackage{layouts}
%\usepackage{longdata}
\usepackage{datatool} % <===============================================
\usepackage{url}
\usepackage{bm}
\usepackage{fancyvrb}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{mathtools}
\usepackage{scalerel}
\usepackage{stackengine}

\DTLnewdb{CS2}
\long\def\newproblem#1#2#3#4#5#6#7#8#9{%
  \DTLnewrow{CS2}%
  \DTLnewdbentry{CS2}{seq}{#1}%
  \DTLnewdbentry{CS2}{yr}{#2}%
  \DTLnewdbentry{CS2}{sub}{#3}%
  \DTLnewdbentry{CS2}{top}{#4}%
 \DTLnewdbentry{CS2}{mar}{#5}%
\DTLnewdbentry{CS2}{qus}{#6}%
\DTLnewdbentry{CS2}{url}{#7}%
\DTLnewdbentry{CS2}{exp}{#8}%
\DTLnewdbentry{CS2}{ans}{#9}%
}

\newproblem{1}{2017-ii}{DE}{number}{1}{{The representation of the value of a 16-bit unsigned integer $X$ in hexadecimal number system is BCA9. The representation of the value of $X$ in octal number system is}\\
(A)571244\\
(B)736251\\
(C)571247\\
(D)136251\\
\hspace*{\fill} GATE 2017-II,1 MARK\\}{\url{http://gatefreaks.com/index.php?qa=9446&qa_1=de-gate-2017-2-1}}{$( BCA9)_{16}=(1011 \ 1100 \ 1010 \ 1001)_2$\\
   =$(001 \ 011 \ 110 \ 010 \ 101 \ 001)_2 = (136251)_8$.}{Ans:d}


\newproblem{2}{2017-ii}{C}{fun}{1}{{Match the following:}\\
\begin{tabular}{|p{0.05in}|p{0.85in}|p{0.05in}|p{1.5in}|p{0.15in}|p{1.0in}|p{1.0in}}
  \hline
P.& static char var;    &i.& Sequence of memory locations to store addresses\\ \hline
Q.& m=malloc(10); m=NULL;&  ii.& A variable located in data section of memory\\ \hline
R.& char *ptr[10];  &iii.& Request to allocate a CPU register to store data\\ \hline
S.& register int varl;  &iv.& A lost memory which cannot be freed\\
  \hline
\end{tabular}\\
(A)P-ii; Q-iv; R-i; S-iii\\
(B)P-ii; Q-i; R-iv; S-iii\\
(C)P-ii; Q-iv; R-iii; S-i\\
(D)P-iii; Q-iv; R-i; S-ii\\
\hspace*{\fill} GATE 2017-II,1 MARK\\}{\url{http://gatefreaks.com/index.php?qa=9447&qa_1=c-gate-2017-2-2}}{static char var = A: variable located in data section of memory.\\
m= malloc(10); m= null : A lost memory which cannot be freed because memory location m is not being freed.\\
Char *Ptr[10]: Sequence of  memory locations to store addresses, it can store 10 addresses.\\
register int var1 :register storage class is used so request to alloacte a CPU register to store data\\
Option a is correct.\\
}{Ans:a}


\begin{document}

\begin{enumerate}
\DTLforeach[\DTLisclosedbetween{\seq}{1}{100}]%
           {CS2}%
           {\seq=seq,\yr=yr,\sub=sub, \top=top, \mar=mar,\qus=qus, \ans=ans}%
          {\DTLifstringeq{\yr}{2017-ii} { \item \qus }{}}
\end{enumerate}
\end{document}

给出结果(没有错误):

在此处输入图片描述

相关内容