2

If one has an foreign acronym (here english) coupled with a german word one uses a - between both. Now I have the problem that the first occurrence of an acronym falls together with a coupled german word. In this case the whitespace between long form of the acronym and the acronym in parentheses needs to be removed (see MWE). So I'm looking for an optional argument for \cgls or another command like \cglsnw to delete this whitespace.

MWE:

\documentclass[a4paper]{article}

\usepackage[english,ngerman]{babel}

\usepackage{glossaries}

\newacronymstyle{emfirst-long-sp-short}
{%
  \GlsUseAcrEntryDispStyle{long-sp-short}%
}%
{%
  \GlsUseAcrStyleDefs{long-sp-short}%  
    \renewcommand*{\genacrfullformat}[2]{%
        \emph{\glsentrylong{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
    \renewcommand*{\Genacrfullformat}[2]{%
        \emph{\Glsentrylong{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
    \renewcommand*{\genplacrfullformat}[2]{%
        \emph{\glsentrylongpl{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
    \renewcommand*{\Genplacrfullformat}[2]{%
        \emph{\Glsentrylongpl{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
}

\renewcommand*{\glsacspace}[1]{~}

\setacronymstyle{emfirst-long-sp-short}

\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{#4}}}

\makeglossaries

\glsenableentrycount

\newforeignacronym{am}{AM}{Application Management}{english}
\newforeignacronym{svm}{SVM}{Support Vector Machine}{english}


\begin{document}

The output from glossaries: \cgls{am}-Problem. \cgls{am}

Required output (without whitespace): \emph{Application Management}(AM)-Problem.

Required output for acronyms which are not coupled (so here with whitespace): \cgls{svm}. \cgls{svm}




\printglossaries
\end{document}
9
  • Which whitespace? I see Application Management-Problem
    – user31729
    Commented Jan 4, 2016 at 23:05
  • @ChristianHupfer I'm sorry I forget to add a second \cgls{am}. The command counts the times the acronym is used so I should use it at least two times. Commented Jan 4, 2016 at 23:17
  • A brute force method would be to remove the ~ in \glsacspace definition
    – user31729
    Commented Jan 4, 2016 at 23:42
  • @ChristianHupfer That would work for this example, but please consider the normal case where the acronym is not coupled with a german word. In that case the white space should be there. I will edit the MWE to make it clear. Commented Jan 4, 2016 at 23:45
  • 1
    I'll try to think about it later on. The mixing style of English and German is awful, in my point of view (I am German) ;-)
    – user31729
    Commented Jan 5, 2016 at 0:02

2 Answers 2

1

A proposition: Use a redefinition of \cgls that has an 3rd argument which is optional and redefine \glsacspace to act whether the \glsentrycurrcount is 0 or greater than 0.

This is not sufficient, however, since \cgls{am}-foo will not react on the -foo part without looking farther ahead, therefore use it this way

\cgls{am}[Problem].

\documentclass[a4paper]{article}

\usepackage[english,ngerman]{babel}
\usepackage{letltxmacro}
\usepackage{xparse}
\usepackage{glossaries}

\renewcommand*{\glsacspace}[1]{~}


\makeatletter
\LetLtxMacro\glossaries@@cgls\cgls
\let\glossaries@@glsacspace\glsacspace




\newif\ifthirdargused%

\RenewDocumentCommand{\cgls}{O{}mo}{%
  \IfValueT{#3}{%
    \thirdargusedtrue%
  }%
  \ifthirdargused
  \begingroup
  \renewcommand*{\glsacspace}[1]{%
    \ifnum\glsentrycurrcount{##1} > 0% Is it > 0 then use the predefined spacing. 
    \glossaries@@glsacspace{##1}%
    \fi
  }%
  \glossaries@@cgls[#1]{#2}-#3%
  \endgroup
  \else
  \glossaries@@cgls[#1]{#2}%
  \fi
  \thirdargusedfalse%
  \let\glsacspace\glossaries@@glsacspace%
}

\makeatother


\newacronymstyle{emfirst-long-sp-short}
{%
  \GlsUseAcrEntryDispStyle{long-sp-short}%
}%
{%
  \GlsUseAcrStyleDefs{long-sp-short}%  
    \renewcommand*{\genacrfullformat}[2]{%
        \emph{\glsentrylong{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
    \renewcommand*{\Genacrfullformat}[2]{%
        \emph{\Glsentrylong{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
    \renewcommand*{\genplacrfullformat}[2]{%
        \emph{\glsentrylongpl{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
    \renewcommand*{\Genplacrfullformat}[2]{%
        \emph{\Glsentrylongpl{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
}


\glsenableentrycount



\setacronymstyle{emfirst-long-sp-short}

\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{#4}}}

\makeglossaries


\newforeignacronym{am}{AM}{Application Management}{english}
\newforeignacronym{svm}{SVM}{Support Vector Machine}{english}


\begin{document}

The output from glossaries: \cgls{am}[Problem]. 

Second usage: \cgls{am}

Required output (without whitespace): \emph{Application Management}(AM)-Problem.

Required output for acronyms which are not coupled (so here with whitespace): \cgls{svm}. 

Second usage: \cgls{svm}

%\cgls{am}-Problem

%\cgls{am}


\printglossaries
\end{document}

enter image description here

1
  • @user2653422: I thank you since I learned new features of glossaries again ;-)
    – user31729
    Commented Jan 6, 2016 at 23:12
1

Here's another possibility that doesn't modify internals.

\documentclass[a4paper]{article}

\usepackage[english,ngerman]{babel}

\usepackage{glossaries}

\newcommand*{\ishyphen}[2]{\ifdefstring{\glsinsert}{-}{#1}{#2}}

\newacronymstyle{emfirst-long-sp-short}
{%
  \GlsUseAcrEntryDispStyle{long-sp-short}%
}%
{%
  \GlsUseAcrStyleDefs{long-sp-short}%  
    \renewcommand*{\genacrfullformat}[2]{%
        \emph{\glsentrylong{##1}}\ishyphen{}{##2\glsacspace{##1}}%
        (\protect\firstacronymfont{\glsentryshort{##1}})\ishyphen{-}{}%
    }%
    \renewcommand*{\Genacrfullformat}[2]{%
        \emph{\Glsentrylong{##1}}\ishyphen{}{##2\glsacspace{##1}}%
        (\protect\firstacronymfont{\glsentryshort{##1}})\ishyphen{-}{}%
    }%
    \renewcommand*{\genplacrfullformat}[2]{%
        \emph{\glsentrylongpl{##1}}\ishyphen{}{##2\glsacspace{##1}}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})\ishyphen{-}{}%
    }%
    \renewcommand*{\Genplacrfullformat}[2]{%
        \emph{\Glsentrylongpl{##1}}\ishyphen{}{##2\glsacspace{##1}}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})\ishyphen{-}{}%
    }%
}

\renewcommand*{\glsacspace}[1]{~}

\setacronymstyle{emfirst-long-sp-short}

\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{#4}}}

\makeglossaries

\glsenableentrycount

\newforeignacronym{am}{AM}{Application Management}{english}
\newforeignacronym{svm}{SVM}{Support Vector Machine}{english}


\begin{document}

The output from glossaries: \cgls{am}[-]Problem. \cgls{am}

Required output (without whitespace): \emph{Application Management}(AM)-Problem.

Required output for acronyms which are not coupled (so here with whitespace): \cgls{svm}. \cgls{svm}

\printglossaries
\end{document}

This redefines the commands used in the full format to check \glsinsert (which is set to the final optional argument of commands like \gls/\cgls). This is actually the second argument of \genacrfullformat etc, so the test could be made against that instead in the event that it's used outside of \cgls.

image of result

1
  • Tried this solution today and found a part in my text where suddenly half of a line is missing and after that the paragraph continues normally. However, there is no command from the glossaries package in that paragraph. I couldn't reproduce this issue with a MWE. So some strange side effects take place due to the solution. Commented Jan 15, 2016 at 21:39

You must log in to answer this question.

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