1

I set custom gls text format with the following command:

\renewcommand*{\glstextformat}[1]{\textcolor{red}{\textbf{#1}}}

But, sometimes, I don't want this format locally for a Tikzpicture, a table or the glossary list for example.

Here a MWE:

\documentclass{article}
\usepackage[style=tree]{glossaries-extra}
\usepackage{xcolor}
\usepackage{tikz}

\makenoidxglossaries

\newglossaryentry{subsytem}{name={Subssytems},description={\glspar},sort={4}}
\newglossaryentry{compressor}
{
  name={Compressor},
  text={compressor},
  sort={compressor},
  description={Air Compressor},
  symbol={cp},
  parent=subsytem
}
\newglossaryentry{compressor_motor}
{
  name={Compressor Motor},
  sort={compressor motor},
  text={compressor motor},
  description={Motor of the \Gls{compressor}},
  symbol={cm},
  parent=subsytem
}

% My custom gls text format !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
\renewcommand*{\glstextformat}[1]{\textcolor{red}{\textbf{#1}}}

\begin{document}

In text I want custom gls format (bold and red) :
\gls{compressor_motor}
\gls{compressor}


But in tables, tikzfigure, glossary I don't want it (I want default format) :\\
\begin{tabular}{rr}
  \hline
 \Glssymbol{compressor} & 1 \\
  \hline
1 & 2.36  \\
   \hline
\end{tabular}


\begin{tikzpicture}%
    \node (CpMap) [draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em] {\Glssymbol{compressor}};
\end{tikzpicture}%

\printnoidxglossary

\end{document}

So, instead of this result:

enter image description here

I would like something like that:

enter image description here

I obtain this result by enclosing the part, where I dont want gls formatting, by these two lines (for exemple with a Tikzfigure):

\renewcommand*{\glstextformat}[1]{{#1}}% Set none gls text format
\begin{tikzpicture}%
    \node (CpMap) [draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em] {\Glssymbol{compressor}};
\end{tikzpicture}%
\renewcommand*{\glstextformat}[1]{\textcolor{red}{\textbf{#1}}}% Restore custom gls text format

Which is really not practical.

I tried to create a new environment which do this enclosing, but I didn't succeed...

EDIT #1 01/28/22 - Clarification: I specify that I use the "colored" format (see at the very beginning) most often. So I would prefer that this format be available "by default" when I use all the classic commands (\Gls, \gls, \glssymbol, etc.). (This is why I redefining the global default format of gls links with \glstextformat.) And only in certain cases, I would like to be able to remove this "colored" format for another format that I have chosen (a "normalfont" would also suffice for my needs). Indeed, it would be too cumbersome for me to have to use other commands (other than the classic gls commands) to use the "colored" format when it's the one I use most often. On the contrary, I don't mind having to do an additional manipulation when I DO NOT want the "colored" format because it's a rarer case for me...

EDIT #2 01/28/22 - Feedback: DG's solution- with the use of \gls[textformat={normalfont}]{compressor} - answers my question. However, after some test I see that it not well suits my needs (not fully visible in my original question). In fact I often define an gls entry by another one like (for exemple with the name field and the description field):

\newglossaryentry{compressor_motor}
{
  name={\glsname[textformat={normalfont}]{compressor} Motor},
  sort={compressor motor},
  text={compressor motor},
  description={Motor of the \Gls[textformat={normalfont}]{compressor}},
  symbol={cm},
  parent=subsytem
}

So, if I do that I will obtain the following result:

enter image description here

With the following code:

\documentclass{article}
\usepackage[style=tree]{glossaries-extra}
\usepackage{xcolor}

\makenoidxglossaries

\newglossaryentry{subsytem}{name={Subssytems},description={\glspar},sort={4}}
\newglossaryentry{compressor}
{
  name={Compressor},
  text={compressor},
  sort={compressor},
  description={Air Compressor},
  symbol={cp},
  parent=subsytem
}
\newglossaryentry{compressor_motor}
{
  name={\glsname[textformat={normalfont}]{compressor} Motor},
  sort={compressor motor},
  text={compressor motor},
  description={Motor of the \Gls[textformat={normalfont}]{compressor}},
  symbol={cm},
  parent=subsytem
}

% My custom gls text format !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
\renewcommand*{\glstextformat}[1]{\textcolor{red}{\textbf{#1}}}

\begin{document}

\glsdesc{compressor_motor}

\printnoidxglossary

\end{document}

As you can see some font (bold) problems occurs (red ellipsis only, rectangle is Ok) as Simon Dispa pointed out in comment. But the [textformat={normalfont}] solution is powerfull because it permits to obtain the red color in text - when \glsdesc is used - but not the bold format.

So, I don't know what to do... Maybe I can use the Simon Dispa solution and create new fields like \glscol, \glssymbolcol \glsnamecol, etc. for all my needs and don't touch the global font with redefining the \glstextformat command. However, this method is quite cumbersome for daily use...

I would be glad to have a solution to locally change the global gls link font as a new environment or something... But if it's not possible I'm ready to let go...

4
  • glossaries-extra has some formatting options that may help you: dickimaw-books.com/gallery/index.php?label=sample-name-font
    – DG'
    Jan 27, 2022 at 10:39
  • @DG Thanks for the tip !
    – zetyty
    Jan 27, 2022 at 21:08
  • The problem with Dg's answer is that "Compresor" is color red in the Glossary list. Jan 28, 2022 at 16:47
  • @Simon You’re right, I did a second edit of my question... Thanks !
    – zetyty
    Jan 28, 2022 at 20:14

3 Answers 3

2

Instead of redefining the global default format you can define a new key.

a

The new key (col) allows the definition of \glscol applying the boldface and the color.

\documentclass{article}
\usepackage[style=tree]{glossaries-extra}   

%*************************************** added <<<<<<<<<<<<<<<<<<
\glsaddkey*% default value needs expanding
{col}% key
{\glsentrytext{\glslabel}col}% default value
{\glsentrycol}% command analogous to \glsentrytext
{\Glsentrycol}% command analogous to \Glsentrytext
{\glscol}% command analogous to \glstext
{\Glscol}% command analogous to \Glstext
{\GLScol}% command analogous to \GLStext
%***************************************
    
\usepackage{xcolor}
\usepackage{tikz}

\makenoidxglossaries

\newglossaryentry{subsytem}{name={Subssytems},description={\glspar},sort={4}}
\newglossaryentry{compressor}
{
    name={Compressor},
    sort={compressor},
    text={compressor},
    col={\bfseries \textcolor{red}{compressor}}, % added <<<<<<<<<<<<<<<<<
    description={Air Compressor},
    symbol={cp},
    parent=subsytem
}
\newglossaryentry{compressor_motor}
{
    name={Compressor Motor},
    sort={compressor motor},
    text={compressor motor},
    col={\bfseries \textcolor{red}{compressor motor}},
    description={Motor of the \Gls{compressor}}, , % added <<<<<<<<<<<<<<<<<
    symbol={cm},
    parent=subsytem
}
    
\begin{document}
    
    In text I want custom gls format (bold and red) :   
    \glscol{compressor_motor} % changed <<<<<<<<<<<<<<<<<<<<<<<<<
    \glscol{compressor} % changed <<<<<<<<<<<<<<<<<<<<<<<<< 
    
    But in tables, tikzfigure, glossary I don't want it (I want default format) :\\
    \begin{tabular}{rr}
        \hline
        \Glssymbol{compressor} & 1 \\
        \hline
        1 & 2.36  \\
        \hline
    \end{tabular}
    
    
    \begin{tikzpicture}%
        \node (CpMap) [draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em] {\Glssymbol{compressor}};
    \end{tikzpicture}%
    
    \printnoidxglossary
    
\end{document}
3
  • That's an interresting solution thank you ! However, I will use most of the time the "color form" with \glssymbol, \glsname, etc. I need to remove the color only in particular case (so not most of the time) so, I would prefer a solution where I need to use a non regular field if I DO NOT want the color and not otherwise, if you understand me... Anyway your solution is the best I have for the moment so thanks again !
    – zetyty
    Jan 27, 2022 at 20:52
  • 1
    @Sylvain Rigal I do not fully understand. Could you expand your question and supply an example of the desired output? Jan 27, 2022 at 21:23
  • I edited my question. I hope it will be clearer. The solution proposed by DG' can suit my needs I think. If you don't want to propose something else I think I will accept his answer. The only thing which would be improve for my needs in DG' 's answer is the possibility to choose another textformat instead of just "normalfont". Thanks again a lot for your proposition !
    – zetyty
    Jan 28, 2022 at 16:30
1

With glossaries-extra you can pass an optional argument textformat to your gls-like commands to format the entry locally:

\documentclass{article}
\usepackage[style=tree]{glossaries-extra}
\usepackage{xcolor}
\usepackage{tikz}

\makenoidxglossaries

\newglossaryentry{subsytem}{name={Subssytems},description={\glspar},sort={4}}
\newglossaryentry{compressor}
{
  name={Compressor},
  text={compressor},
  sort={compressor},
  description={Air Compressor},
  symbol={cp},
  parent=subsytem
}
\newglossaryentry{compressor_motor}
{
  name={Compressor Motor},
  sort={compressor motor},
  text={compressor motor},
  description={Motor of the \Gls{compressor}},
  symbol={cm},
  parent=subsytem
}

% My custom gls text format !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
\renewcommand*{\glstextformat}[1]{\textcolor{red}{\textbf{#1}}}

\begin{document}

In text I want custom gls format (bold and red) :
\gls{compressor_motor}
\gls{compressor}


But in tables, tikzfigure, glossary I don't want it (I want default format) :\\
\begin{tabular}{rr}
  \hline
 \Glssymbol{compressor} & 1 \\
  \hline
1 & 2.36  \\
   \hline
\end{tabular}


\begin{tikzpicture}%
    \node (CpMap) [draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em] {\Glssymbol[textformat={normalfont}]{compressor}};
\end{tikzpicture}%

\printnoidxglossary

\end{document}

enter image description here


You can also use your own formatting commands, like blackbold in this example:

\documentclass{article}
\usepackage[style=tree]{glossaries-extra}
\usepackage{xcolor}
\usepackage{tikz}

\makenoidxglossaries

% My custom gls text format !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
\renewcommand*{\glstextformat}[1]{\textcolor{red}{\textbf{#1}}}
\newcommand{\blackbold}[1]{\textcolor{black}{\textbf{#1}}}

\newglossaryentry{subsytem}{name={Subssytems},description={\glspar},sort={4}}
\newglossaryentry{compressor}
{
  name={Compressor},
  text={compressor},
  sort={compressor},
  description={Air Compressor},
  symbol={cp},
  parent=subsytem
}
\newglossaryentry{compressor_motor}
{
  name={\glsname[textformat={blackbold}]{compressor} Motor},
  sort={compressor motor},
  text={compressor motor},
  description={Motor of the \Gls[textformat={blackbold}]{compressor}},
  symbol={cm},
  parent=subsytem
}



\begin{document}

In text I want custom gls format (bold and red) :
\gls{compressor_motor}
\gls{compressor}


But in tables, tikzfigure, glossary I don't want it (I want default format) :\\
\begin{tabular}{rr}
  \hline
 \Glssymbol{compressor} & 1 \\
  \hline
1 & 2.36  \\
   \hline
\end{tabular}


\begin{tikzpicture}%
    \node (CpMap) [draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em] {\Glssymbol[textformat={normalfont}]{compressor}};
\end{tikzpicture}%


\printnoidxglossary

\end{document}

enter image description here

5
  • I think this solution can suit my needs thank you! I have to do some tests before confirming. The only thing which would be improve for my needs is the possibility to choose another textformat instead of just "normalfont" Thanks again !
    – zetyty
    Jan 28, 2022 at 16:31
  • Of course, you can format the text however you like
    – DG'
    Jan 28, 2022 at 19:36
  • thanks ! Which attribute can I pass after the "textformat=" because I don't find the info in glossaries-extra manual? For exemple to change the color. Also, I edit my question (#2 edit) because of the glossary print problem pointed out by Simon. Thanks a lot !
    – zetyty
    Jan 28, 2022 at 20:18
  • The answer is glossaries-user: textformat= takes the name of a control sequence. So you can define a new command that does the formatting.
    – DG'
    Jan 28, 2022 at 20:25
  • Ok I understand. Thank you for your time !
    – zetyty
    Jan 28, 2022 at 20:46
1

UPDATE 1: environment with optionnal argument

I found how to create a new environment for my needs (if it could help someone)!

First I created 3 commands for global and local custom glossary links formats:

  • GLOBAL gls format (blod red): \newcommand*{\myGLOBALDefaultGlsTextFormat}[1]{{\bfseries{\textcolor{red}{#1}}}}
  • Local DEFAULT gls format (italic green): \newcommand*{\myLocalDEFAULTGlsTextFormat}[1]{\textit{\textcolor{green}{#1}}}
  • Local CUSTOM gls format (underline blue): \newcommand*{\myLocalCUSTOMGlsTextFormat}[1]{\underline{{\textcolor{blue}{#1}}}}

I set globally gls links format to bold red with:

\renewcommand*{\glstextformat}[1]{\myGLOBALDefaultGlsTextFormat{#1}}% Define global gls links format

And then the new environment with optionnal argument (needs xparse package):

  • Set Local DEFAULT gls format (italic green) IF NO argument passed;

  • Set Local CUSTOM gls format (underline blue) IF command \myLocalCUSTOMGlsTextFormat is passed as argument for exemple (any other format could be passed BTW);

Here the environment declaration code (see egreg answer for details):

\usepackage{xparse}
\NewDocumentEnvironment{localGlsTextFormat}{o}%
  {\IfNoValueTF{#1}{%start code no opt arg
\let\oldglstextformat\glstextformat
\renewcommand\glstextformat[1]{\myLocalDEFAULTGlsTextFormat{##1}}}{%start code with #1
\let\oldglstextformat\glstextformat
\renewcommand\glstextformat[1]{#1{##1}}}}%
  {\IfNoValueTF{#1}{%end code no opt arg
  }{%end code with #1
  }}%

And here another environment without optionnal argument (no needs for xparse package) which just set the Local DEFAULT gls format (italic green) as the above environment does if no optionnal argument is given:

\newenvironment*{defaultLocalGlsTextFormat}{%
\let\oldglstextformat\glstextformat
\renewcommand\glstextformat[1]{\myLocalDEFAULTGlsTextFormat{##1}}%Set Local format
}%

Here a MWE:

\documentclass{article}
\usepackage[style=tree]{glossaries-extra}
\usepackage{xcolor}
\usepackage{tikz}

\makenoidxglossaries

\newcommand*{\myGLOBALDefaultGlsTextFormat}[1]{{\bfseries{\textcolor{red}{#1}}}}% Global format bold red
\newcommand*{\myLocalDEFAULTGlsTextFormat}[1]{\textit{\textcolor{green}{#1}}}% Local format italic green
\newcommand*{\myLocalCUSTOMGlsTextFormat}[1]{\underline{{\textcolor{blue}{#1}}}}% Local format underline blue

\renewcommand*{\glstextformat}[1]{\myGLOBALDefaultGlsTextFormat{#1}}% Define global gls links format

\usepackage{xparse}
% New environment for local gls link format WITH optionnal argument
\NewDocumentEnvironment{localGlsTextFormat}{o}%
  {\IfNoValueTF{#1}{%start code no opt arg
\let\oldglstextformat\glstextformat
\renewcommand\glstextformat[1]{\myLocalDEFAULTGlsTextFormat{##1}}}{%start code with #1
\let\oldglstextformat\glstextformat
\renewcommand\glstextformat[1]{#1{##1}}}}%
  {\IfNoValueTF{#1}{%end code no opt arg
  }{%end code with #1
  }}%

% New environment for local gls link format WITHOUT optionnal argument
\newenvironment*{defaultLocalGlsTextFormat}{%
\let\oldglstextformat\glstextformat
\renewcommand\glstextformat[1]{\myLocalDEFAULTGlsTextFormat{##1}}%Set Local format
}

% Glossary entries
\newglossaryentry{subsytem}{name={Subssytems},description={\glspar},sort={4}}
\newglossaryentry{compressor}
{
  name={Compressor},
  text={compressor},
  sort={compressor},
  description={Air Compressor},
  symbol={cp},
  parent=subsytem
}
\newglossaryentry{compressor_motor}
{
  name={\glsname{compressor} Motor},
  sort={compressor motor},
  text={compressor motor},
  description={Motor of the \Gls{compressor}},
  symbol={cm},
  parent=subsytem
}

\begin{document}

\textbf{Here global gls formated links (bold red)}:
\glsdesc{compressor_motor};
\glstext{compressor_motor}
\begin{tabular}{rr}
  \hline
 \Glssymbol{compressor} & 1 \\
  \hline
1 & 2.36  \\
   \hline
\end{tabular}
\begin{tikzpicture}%
    \node (CpMap) [draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em] {\Glssymbol{compressor}};
\end{tikzpicture}%
\printnoidxglossary

\vspace{1cm}
\textbf{Here local default gls formated links (italic green) given by the environment without optional argument (no need for xparse package)}:
\begin{defaultLocalGlsTextFormat}
\begin{tabular}{rr}
  \hline
 \Glssymbol{compressor} & 1 \\
  \hline
1 & 2.36  \\
   \hline
\end{tabular}
\end{defaultLocalGlsTextFormat}

\vspace{1cm}
\textbf{Here local default gls formated links (italic green) with the xparse environment but without passing an optionnal argument}:
\begin{localGlsTextFormat}
\glsdesc{compressor_motor};
\glstext{compressor_motor}
\end{localGlsTextFormat}

\vspace{1cm}
\textbf{Here local custom gls formated links (underline blue) with the xparse environment with an optionnal argument}:

\begin{localGlsTextFormat}[\myLocalCUSTOMGlsTextFormat]
\begin{tikzpicture}%
    \node (CpMap) [draw, fill=blue!20, text width=5em,text centered, minimum height=2.5em] {\Glssymbol{compressor}};
\end{tikzpicture}%

\printnoidxglossary
\end{localGlsTextFormat}

\vspace{1cm}
\textbf{Here again global gls formated links}:
\glsdesc{compressor_motor};
\glstext{compressor_motor}
\end{document}

Results:

enter image description here

You must log in to answer this question.

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