1

It seems to me that the instruction below produces some extra space.

\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 content:

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

Result

4
  • your code can not be tested as db.csv doesn't exist. Commented Aug 6, 2021 at 7:26
  • gostID,number,title,year etc is a content of db.csv file. Commented Aug 6, 2021 at 7:36
  • don't add \xspace everywhere. It adds spaces where you don't want them. Commented Aug 6, 2021 at 7:52
  • Without xspace the result is same. Commented Aug 6, 2021 at 8:01

1 Answer 1

2

If I remove \xspace and also suppress various spurious spaces with % the spaces disappear:

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

enter image description here

3
  • Both actions didn't solve this one in my case... Commented Aug 6, 2021 at 8:26
  • 1
    works fine for me, the screenshot is true. Did you copy and paste from my answer? And is your tex system up-to-date? Commented Aug 6, 2021 at 8:28
  • Yep, I found the lost % symbol. It was funny. Commented Aug 6, 2021 at 11:51

You must log in to answer this question.

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