2

I'm using the glossaries package to enter acronyms, in an scrbook document. For now, I'm using \gls in the text, and \acrshort & \acrlong in tables (to manually control the form).

Because I use a lot of acronyms in my thesis, I would like LaTeX, when using \gls, to display the long version of the acronym in the margin (right or left since it is a two side document, and with the possibility to make the text smaller), along the paragraph, except for the first time in each chapter since the long version is automatically entered in the text, and only in the \mainmatter.

Here is a 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{setspace}
    \setstretch{1.5}
    \usepackage[bottom]{footmisc}

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

\newglossarystyle{long-ucdesc}{%
  \setglossarystyle{long}%
    \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \Glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
  }%
}

\newacronym{unesco}{unesco}{United Nations Educational, Scientific and Cultural Organization}

\begin{document}
\frontmatter
\mainmatter
\gls{unesco} ......
\gls{unesco}
\appendix
\backmatter
\printglossary[type=acronym, style=long]\label{listofacronyms}

\end{document}

I have no idea where to start to do this. I see that the package marginnote can do something close with notes, but that's it.

EDIT: I see that some have used the package glossaries-extra, for instance the answer here, but I can't make it work (some functions seem deprecated).

1 Answer 1

1

We need to redefine acronym's format using \defglsentryfmt

\makeatletter  
\defglsentryfmt[acronym]{\glsgenacfmt  
\ifglsused{\glslabel}{\if@mainmatter\marginpar{{\scriptsize
\textsf{\glsentrylong{\glslabel}}}}\fi}{}}
\makeatother

If we need the original definition, for example in tabular like environment we need to use \mhacrshort and \mhacrshort defined with

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

Here is a complete code that doesn't writes the long form to the margin more than one time per page.

\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}
8
  • Perfect, thanks!
    – mhr
    Jan 15, 2020 at 21:18
  • it seems that a space is added after the short version on the second call of \gls. You can reproduce the error by inserting test \gls{onu} and \gls{onu}. \gls{onu}. at the beginning of the document. Thanks.
    – mhr
    Feb 18, 2020 at 11:11
  • 1
    Yes Thank you. We need to type \expandafter\gdef\csname mhused\glslabel\endcsname{}%
    – touhami
    Feb 20, 2020 at 17:33
  • Hi @touhami, do you think it would be possible to have the long version in the margin only for a particular category of acronym? Thanks!
    – mhr
    Jan 21, 2021 at 10:06
  • @mhr I think yes. Sorry i was offline.
    – touhami
    Jan 23, 2021 at 13:50

You must log in to answer this question.

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