0

I would like to make a glossary of a text where sometimes operations are described. One of this is the "overline" operation.

In the text, I would like to write:

\gls{Overline}[u]

such that only the bar created by the \overline command is linked to the glossary, and not the argument under it (here u).

Picture bellow shows the kind of result I want (links in red color):

Wanted result

The following code is largely inspired by Symbols with optional parameter in glossaries with \newglossary issue:

\documentclass{article}
\usepackage[hidelinks, colorlinks=true]{hyperref}

\usepackage[abbreviations]{glossaries-extra}

\makeglossaries \glsnoexpandfields

\newcommand{\glsdefaultarg}{i} \newcommand{\glsarg}{\glsdefaultarg}

\newglossaryentry{Overline}{ category=arg,% requires an argument name=\ensuremath{\overline{\glsdefaultarg}}, text=\ensuremath{\overline{\glsarg}}, description={Overline description} } % modify the entry's format

\preto\glsentryfmt{% \glsifcategory{\glslabel}{arg}% if category set to "arg" {% \ifdefempty\glsinsert {\let\glsarg\glsdefaultarg}% {% \let\glsarg\glsinsert \let\glsinsert\empty }% }% {}% }

\begin{document}

(\gls{Overline})

\phantom{}

(\gls{Overline}[a])

\phantom{}

(\gls{Overline}[(u, v)])

\phantom{}

(\gls{Overline}[f])

\phantom{}

(\gls{Overline})

\printglossaries \end{document}

It outputs this:

LaTeX output

As you can see, both the bar produced by \overline and the text under it are linked to the glossary (in red thanks to hyperref package).

Note that the printed glossary is correct.

The key idea is perhaps to create a macro that simulates \overline result (see with tikz here: a bolder \overline), and customise the glossary format in the text. But I don't really know how to do this.

Thank you for reading me, Have a nice day

SebGlav
  • 19,186
vepain
  • 23

1 Answers1

0

I found a way to simulate \overline behaviour and make the line clickable and coloured.

While it is quite ugly, it works, so I tag the question answered. But I would be really enjoyed if someone has a cleaner way to do this.

The code (note that I created a simpler MWE without glossaries arg category). Furthermore, here the colour of the glossary text entry is not the same as the one of other link (page number in Glossary section).

% ============================================================================ %
%                                    CONFIG                                    %
% ============================================================================ %
\documentclass{article}
\usepackage[hidelinks, colorlinks=true]{hyperref}

\usepackage[abbreviations]{glossaries-extra} \usepackage{tikz} \usetikzlibrary{calc} % because of 'let' in tikzpicture env.

% ============================================================================ % % HYPERREF % % ============================================================================ % \newcommand{\customglshrefcol}{blue} % Cleaner bc we will reuse this command

% ============================================================================ % % GLOSSARIES % % ============================================================================ % \makeglossaries%

% ---------------------------------------------------------------------------- % % Link Color % % ---------------------------------------------------------------------------- % \renewcommand*{\glstextformat}[1]{\textcolor{\customglshrefcol}{#1}}

% ---------------------------------------------------------------------------- % % Entry % % ---------------------------------------------------------------------------- % \newcommand{\overbardefault}{\ensuremath{,\cdot,}} \newglossaryentry{overbar}{ name=\ensuremath{\overline{\overbardefault}},% for the printglossaries text={},% because \Overline command will replace \gls behaviour description={Overline description} }

% ---------------------------------------------------------------------------- % % Simulate Overline % % ---------------------------------------------------------------------------- % \newcommand\Overline[2][0.5pt]{% \begin{tikzpicture}[baseline=(a.base)] % % The text under the line % \node[inner xsep=0pt,inner ysep=1.5pt] (a) {$#2$}; % % Write link on the overline % \path let \p1=(a.north west), \p2=(a.north east), \n1={veclen(\x2-\x1,\y2-\y1)} in node[outer sep=0pt,inner xsep=0pt,align=left,anchor=west,minimum width=\n1,minimum height=1ex] at (a.north west) (link) {% \glshyperlink[<text>]{<label>} \glshyperlink[% \gls{overbar}\hphantom{\hspace*{\n1}}% we use \gls to add page number in Glossary section ]{overbar}% }; % % Draw overline % \draw[line width= #1, color=\customglshrefcol] (a.north west) -- (a.north east); \end{tikzpicture}% }

% ============================================================================ % % BODY % % ============================================================================ % \begin{document}

(\Overline{\overbardefault} \quad \overline{\overbardefault})

\phantom{}

(\Overline{a} \quad \overline{a})

\phantom{}

(\Overline{(u, v)} \quad \overline{(u, v)})

\phantom{}

(\Overline{f} \quad \overline{f})

\printglossaries

\end{document}

It outputs:

enter image description here

The code is highly inspired by https://tex.stackexchange.com/a/526333/232319

vepain
  • 23
  • to subscript/power the overlined text with the new \Overline command, it is necessary to call \text before. e.g. L_{\text{\Overline{f}}} – vepain Oct 17 '22 at 17:22
  • 1
    See my solution over at https://tex.stackexchange.com/a/668364/76043 – ralphS16 Dec 13 '22 at 00:46