DTLgetvalueforkey 产生不必要的空格

DTLgetvalueforkey 产生不必要的空格

在我看来,下面的指令产生了一些额外的空间。

\documentclass[12pt,a4paper,russian]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[russian]{babel}

\usepackage{datatool,xspace,cleveref}


\newcommand{\createGostDb}[1]{%
    % param-1: DB
    \DTLgnewdb{#1}
    \DTLaddcolumn{#1}{number}
    \DTLaddcolumn{#1}{app}
}

\newcommand{\loadGostDb}[1]{\DTLloaddb{db}{#1}}


% https://tex.stackexchange.com/questions/498022/update-values-in-datatool
\newcommand*\dtlupdaterefsincurrentrow{\dtlupdateentryincurrentrow{app}}
\newcommand\appender[3]{%
    % param-1: DB
    % param-2: gostId
    % param-3: appendable section ref
    \DTLgetvalueforkey{\oldSecRefs}{app}{#1}{number}{#2}%
    \edtlgetrowforvalue{#1}{\dtlcolumnindex{#1}{number}}{#2}%
    \expandafter\dtlupdaterefsincurrentrow\expandafter{\oldSecRefs, \Cref{#3}}%
    \dtlrecombine%
}

\newcommand{\addGost}[3]{
    % param-1: datatool DB
    % param-2: gostId
    % param-3: reference
    \DTLnewrow{#1}%
    \DTLnewdbentry{#1}{number}{#2}
    \DTLnewdbentry{#1}{app}{\Cref{#3}}
}

\newcommand{\getGostNumberById}[1]{%
    \DTLgetvalueforkey{\name}{number}{db}{gostID}{#1}\name\xspace%
}

\newcommand{\getGostYearById}[1]{%
    \DTLgetvalueforkey{\year}{year}{db}{gostID}{#1}\year\xspace%
}

\newcommand{\getGostTitleById}[1]{%
    \DTLgetvalueforkey{\title}{title}{db}{gostID}{#1}\title\xspace%
}

\newcommand{\emplaceGost}[2]{%
    % param-1: gostId
    % param-2: which section appear
    \getGostNumberById{#1}\xspace%
    \dtlgetrowindex{\currentrowidx}{gost}{\dtlcolumnindex{gost}{number}}{#1}%
    \ifx\currentrowidx\dtlnovalue
        % Not Found
        \addGost{gost}{#1}{#2}%
    \else
        % Found in row \currentrowidx.
        \appender{gost}{#1}{#2}%
    \fi
}


\begin{document}
    \loadGostDb{db.csv}
    \createGostDb{gost}
    \Crefname{section}{}{}
    \Crefname{appendix}{App.}{Apps.}

    \section{Some section}
    \subsection{Some subsection}\label{i}
    Why this command produces the extra spaces between the quotes <<\emplaceGost{GOST1552}{i}>>?

    \subsection{Another subsection}\label{ii}
    The same effect you can find here <<\getGostNumberById{GOST1552}>>\ldots

    \appendix
    \section{Show}\label[appendix]{ii}
    <<\emplaceGost{GOST1553}{ii}>>,
    <<\emplaceGost{GOST1552}{ii}>>.
\end{document}

db.csv内容:

\begin{filecontents*}{db.csv}
gostID,number,title,year
GOST1552,ГОСТ 1552,Об этом ГОСТ, 98
GOST1553,ГОСТ 1553,О том ГОСТ, 99
\end{filecontents*}

结果

答案1

如果我删除 \xspace 并且还抑制各种虚假空格,%空格就会消失:

\documentclass[12pt,a4paper,russian]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[russian]{babel}

\usepackage{datatool,xspace,cleveref}


\newcommand{\createGostDb}[1]{%
    % param-1: DB
    \DTLgnewdb{#1}%
    \DTLaddcolumn{#1}{number}%
    \DTLaddcolumn{#1}{app}%
}

\newcommand{\loadGostDb}[1]{\DTLloaddb{db}{#1}}


% https://tex.stackexchange.com/questions/498022/update-values-in-datatool
\newcommand*\dtlupdaterefsincurrentrow{\dtlupdateentryincurrentrow{app}}
\newcommand\appender[3]{%
    % param-1: DB
    % param-2: gostId
    % param-3: appendable section ref
    \DTLgetvalueforkey{\oldSecRefs}{app}{#1}{number}{#2}%
    \edtlgetrowforvalue{#1}{\dtlcolumnindex{#1}{number}}{#2}%
    \expandafter\dtlupdaterefsincurrentrow\expandafter{\oldSecRefs, \Cref{#3}}%
    \dtlrecombine%
}

\newcommand{\addGost}[3]{%
    % param-1: datatool DB
    % param-2: gostId
    % param-3: reference
    \DTLnewrow{#1}%
    \DTLnewdbentry{#1}{number}{#2}%
    \DTLnewdbentry{#1}{app}{\Cref{#3}}%
}

\newcommand{\getGostNumberById}[1]{%
    \DTLgetvalueforkey{\name}{number}{db}{gostID}{#1}\name%
}

\newcommand{\getGostYearById}[1]{%
    \DTLgetvalueforkey{\year}{year}{db}{gostID}{#1}\year%
}

\newcommand{\getGostTitleById}[1]{%
    \DTLgetvalueforkey{\title}{title}{db}{gostID}{#1}\title%
}

\newcommand{\emplaceGost}[2]{%
    % param-1: gostId
    % param-2: which section appear
    \getGostNumberById{#1}%
    \dtlgetrowindex{\currentrowidx}{gost}{\dtlcolumnindex{gost}{number}}{#1}%
    \ifx\currentrowidx\dtlnovalue
        % Not Found
        \addGost{gost}{#1}{#2}%
    \else
        % Found in row \currentrowidx.
        \appender{gost}{#1}{#2}%
    \fi
}


\begin{document}
    \loadGostDb{db.csv}
    \createGostDb{gost}
    \Crefname{section}{}{}
    \Crefname{appendix}{App.}{Apps.}

    \section{Some section}
    \subsection{Some subsection}\label{i}
    Why this command produces the extra spaces between the quotes <<\emplaceGost{GOST1552}{i}>>?

    \subsection{Another subsection}\label{ii}
    The same effect you can find here <<\getGostNumberById{GOST1552}>>\ldots

    \appendix
    \section{Show}\label[appendix]{ii}
    <<\emplaceGost{GOST1553}{ii}>>,
    <<\emplaceGost{GOST1552}{ii}>>.
\end{document}

在此处输入图片描述

相关内容