0

I'm using the solution given here to display long versions of acronyms in the margin, using the glossaries package. It works great, but I would like it to act like this only for the acronym of an organization, and not for others.

Here is the MWE

\documentclass[chapterprefix,twoside,12pt,DIV=12]{scrbook}
\KOMAoptions{headsepline=true, chapterprefix=true}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[onehalfspacing]{setspace}
\usepackage[bottom]{footmisc}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{etoolbox}

\usepackage[acronym,smallcaps]{glossaries}
\makeglossaries

\makeatletter  
\defglsentryfmt[acronym]{\glsgenacfmt  
\ifglsused{\glslabel}{\if@mainmatter
\expandafter\ifx\csname mhused\glslabel\endcsname\relax
\expandafter\gdef\csname mhused\glslabel\endcsname{}%
\xappto\mhclearacrmargin{\global\expandafter\expandafter\expandafter\let\expandafter\noexpand\csname mhused\glslabel\endcsname\relax}\marginpar{{\scriptsize
\textsf{\glsentrylong{\glslabel}}}}\fi\fi}{}}

\patchcmd\@outputpage{\botmark}{\botmark \mhclearacrmargin \gdef\mhclearacrmargin{}}{}{}{}
\makeatother

\newcommand{\mhacrshort}[1]{\acronymfont{\glsentryshort{#1}}}
\newcommand{\mhacrlong}[1]{\glsentrylong{#1}}

\newcommand{\mhclearacrmargin}{}

\newacronym{unesco}{unesco}{United Nations Educational, Scientific and Cultural Organization}
\newacronym{onu}{onu}{Organisation des Nations Unies}

\begin{document}
\frontmatter
\mainmatter
\chapter{test}
\section{test}
\gls{unesco} ...... \gls{onu}

\gls{onu} ... \gls{unesco}

\gls{onu} ... \gls{unesco}

\newpage

\gls{unesco} ...... \gls{onu}

\gls{onu} ... \gls{unesco}

\gls{onu} ... \gls{unesco}
\begin{table}[p]
\begin{tabular}{@{}rcl@{}}
\toprule
\textbf{Colonne 1} & \textbf{Colonne 2} & \textbf{Colonne 3} \\
\midrule
\mhacrlong{onu} & 1 & \mhacrshort{unesco} \\
\mhacrshort{onu} & 4 & \mhacrshort{unesco}  \\
\bottomrule
\end{tabular}
\end{table}

\appendix
\backmatter
\gls{unesco}
\printglossary[type=acronym, style=long]\label{listofacronyms}

\end{document}

I guess we could use the type option to separate the two categories of acronyms (organizations and others), but I don't know where to go from there.

6
  • 2
    Change to the glossaries-extra package, so you have access to the \glsifcategory command. Set as optional arguments [category=show] for UNO and [category=shownot] for ONU respectively. Last but not least replace the content within your \textsf command with \glsifcategory{\glslabel}{show}{\glsentrylong{\glslabel}}{}. That should work.
    – Venez
    Jan 29, 2021 at 10:42
  • Thanks! It seems to work well on the MWE, I'm gonna try it on the document I'm working on. However, it seems the smallcaps option has no effect with glossaries-extra.
    – mhr
    Jan 31, 2021 at 9:35
  • Hmm... perhaps you could try this -> \setabbreviationstyle[acronym]{long-sc-short}? Btw glossaries-extra recommends the use of \newabbreviation instead of \newacronym.
    – Venez
    Feb 1, 2021 at 13:29
  • It returns this error: Error: Undefined abbreviation style 'long-sc-short' \setabbrevionstyle[acronym]{long-sc-short}
    – mhr
    Feb 1, 2021 at 19:36
  • Upps ... my fault. Should have read the right package-doc ^^# (see. section Acronym Style Modifications, table 2.1 in doc for glossaries-extra). For me it works with \setabbreviationstyle{long-short-sc}. And to sum everything up, i will post the completed MWE as a separate answer.
    – Venez
    Feb 2, 2021 at 14:01

1 Answer 1

1

For explanations see comment dialog below initial question.

\documentclass[chapterprefix,twoside,12pt,DIV=12]{scrbook}
\KOMAoptions{headsepline=true, chapterprefix=true}
\usepackage[french]{babel}
\usepackage[onehalfspacing]{setspace}

\usepackage[acronym]{glossaries-extra}
\setabbreviationstyle{long-short-sc}
\makeglossaries

\makeatletter  
\defglsentryfmt[acronym]{\glsgenacfmt  
    \ifglsused{\glslabel}{\if@mainmatter
        \expandafter\ifx\csname mhused\glslabel\endcsname\relax
        \expandafter\gdef\csname mhused\glslabel\endcsname{}%
        \xappto\mhclearacrmargin{\global\expandafter\expandafter\expandafter\let\expandafter\noexpand\csname mhused\glslabel\endcsname\relax}\marginpar{{\scriptsize
                \textsf{\glsifcategory{\glslabel}{show}{\glsentrylong{\glslabel}}{} }}}\fi\fi}{}}

\patchcmd\@outputpage{\botmark}{\botmark \mhclearacrmargin \gdef\mhclearacrmargin{}}{}{}{}
\makeatother

\newcommand{\mhacrshort}[1]{\acronymfont{\glsentryshort{#1}}}
\newcommand{\mhacrlong}[1]{\glsentrylong{#1}}
\newcommand{\mhclearacrmargin}{}

\newacronym[category=show]{unesco}{unesco}{United Nations Educational, Scientific and Cultural Organization}
\newacronym[category=shownot]{onu}{onu}{Organisation des Nations Unies}

\begin{document}
    \chapter{test}
    \gls{unesco} ...... \gls{onu}
        
    \newpage
    \gls{unesco} ...... \gls{onu}
    \printglossary[type=acronym, style=long]\label{listofacronyms}
\end{document}

You must log in to answer this question.

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