0

I am currently trying to use a glossary entry in the labels of a PGFPlot. E.g. ylabel={$\gls{F}_h\ in\ \glsunit{F}}.

I set up glsunit according to How to use glossary entry in siunitx command?. Inside text this is working fine, just not in the PGFPlot. There the symbols only appear as ???.

Further info: I am using tikz externalize for the plots and use a bib file and bib2gls for the symbols.

Is there a way to resolve the symbols inside the PGFPlot?

the stripped down example:

\begin{filecontents*}{symbols.bib}
@entry{F,
    name={\ensuremath{F}},
    description={Force},
    unit={\si{\newton}}
    }

@entry{s,
    name={\ensuremath{s}},
    description={Normalised Distance},
    unit={}
    }
\end{filecontents*}
\documentclass{article}
\usepackage[british]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage[colorlinks=true, linkcolor=black, citecolor=blue, urlcolor=blue]{hyperref}
\usepackage{siunitx}
\usepackage[record, abbreviations, nonumberlist]{glossaries-extra}
    \setabbreviationstyle{long-short}
    \newglossary[slg]{symbols}{syi}{syg}{Symbols}
    \glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}
    \glssetnoexpandfield{unit}
    \newglossarystyle{symbunitlong}{%
        \setglossarystyle{long3col}% base this style on the list style
        \renewenvironment{theglossary}{% Change the table type --> 3 columns
          \begin{longtable}{lp{\glsdescwidth}>{\centering\arraybackslash}p{2cm}}}%
          {\end{longtable}}%
        %
        \renewcommand*{\glossaryheader}{%  Change the table header
          \bfseries Sign & \bfseries Description & \bfseries Unit \\
          \hline
          \endhead%
        }
        \renewcommand*{\glossentry}[2]{%  Change the displayed items
            \glstarget{##1}{\glossentryname{##1}} %
            & \glossentrydesc{##1}% Description
            & \glsunit{##1}  \tabularnewline
        }
    }
    \GlsXtrLoadResources[src={symbols}, type={symbols}]
\usepackage{pgfplots}
    \usepgfplotslibrary{external}
    \pgfplotsset{compat=1.16}
%    \tikzexternalize[
%        mode=list and make,
%%        force remake,
%    ]
\begin{document}
\printunsrtglossary[type=symbols, style=symbunitlong]
    Just a test with \gls{s} and \gls{F} in \glsunit{F}. \\
    %
    \begin{tikzpicture}
        \begin{axis}[
            xlabel={\gls{s}},
            ylabel={$\gls{F}\ in\ \glsunit{F}$},
        ]
            \addplot[color=red,mark=x] coordinates {
                (2,-2.8559703)
                (3,-3.5301677)
                (4,-4.3050655)
                (5,-5.1413136)
                (6,-6.0322865)
                (7,-6.9675052)
                (8,-7.9377747)
            };
        \end{axis}
    \end{tikzpicture}
\end{document}
Stefan Pinnow
  • 29,535
Thorsten
  • 113
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Stefan Pinnow Mar 23 '20 at 16:04
  • If you don't do this there is a lot of work for us (the helpers) and also maybe a lot of guessing what you do. From what you have stated so far I would guess that you have to use /tikz/external/mode=list and make to make it work. See the tikz manual or PGFPlots manual for details. – Stefan Pinnow Mar 23 '20 at 16:09
  • I added a stripped down version of my problem – Thorsten Mar 23 '20 at 16:27
  • /tikz/external/mode = list and make did not resolve the problem. Still only ??? is displayed – Thorsten Mar 23 '20 at 17:05
  • I just adjusted your MWE and removed unnecessary stuff. But also when I compile this one I everywhere just get ??, not only in the tikzpicture or axis environment. Please modify it again and/or describe in comments or the normal text what to do so that at least the stuff outside tikzpicture shows up. – Stefan Pinnow Mar 23 '20 at 17:09
  • first of all thank you for editing it. It seems I removed one line too much. Added \printunsrtglossary[type=symbols, style=symbunitlong] after begin document. Now it works without the externalize. But not with externalize – Thorsten Mar 23 '20 at 17:19
  • Since you didn't state something else I assume that one just has to run LaTeX (several times). But unfortunately then I (still) just receive ??s and nothing in "Symbols" section ... – Stefan Pinnow Mar 23 '20 at 17:43
  • did you run bib2gls filename in between? – Thorsten Mar 23 '20 at 17:46
  • I can confirm that running latex, bib2gls and latex again shows the glossaries stuff everywhere when the external library isn't used and it doesn't work in the axis environment when the external library is used. Unfortunately I don't know why. Maybe @NicolaTalbot has an idea why !?!? – Stefan Pinnow Mar 23 '20 at 18:34

0 Answers0