3

I use the ampersand in the body of my these when I need to say "and"… often, you can imagine! After open my document, I use:

makeampletter \def\makeampletter{\catcode`\&11\relax}

If I need to put a table, I turn:

makeampcolsep \def\makeampcolsep{\catcode`\&4\relax}

That's my way, because I don't know how to transform my "and", or my "et" in french, in "&" (historically, "&" is the ligature of "et"). Furthermore, if I transform all "and" or "et" in "&", I'll turn all "Brandies" in "Br&ies" and all "Cabernet" in "Cabern&", perplexing. &, I don't want to start my sentences with "&". There could be a solution: transform as a ligature only if the conjunction is between spaces or punctuation « et » or " and " or « -et- », and if the world is in lower case... If you can build this solution, I'll take it. So, I write with "&" in my text. Sometimes, I know, it's a bad idea, in tables, in titles, in labels etc. I bypass. But, I need to use "&" in glossaries descriptions. I show in the MWE a little program who explain why \&, \&\, or {\&} are not good solutions for me (space management, correspondence with other functions).

Here is my question: to freely use the ampersand, how to automatise the use of & sign in all descriptions of glossary entries ? Use my friendly programs makeampletter & makeampcolsep, but where ?

% !TEX encoding = UTF-8 Unicode 
% !TEX TS-program = arara
\documentclass{scrbook} 
\def\makeampletter{\catcode`\&11\relax}
\newcommand\ampersandtrip[2]{\newglossaryentry{#1}{name=#1,type=main,description={#2}}#2\footnote{\gls{#1}}}

\usepackage{glossaries}
\makeglossaries
\newglossaryentry{and}{name=and,description={I want to use my &!}}% \&
\newglossaryentry{et}{name=et,description={Je veux utiliser mon & !}}% \&

\begin{document}
\makeampletter
\gls{and} & \gls{et}

\section*{Trip 1}\glsentrydesc{trip1}\\\ampersandtrip{trip1}{You \& me}
\section*{Trip 2}\glsentrydesc{trip2}\\\ampersandtrip{trip2}{Toi \&  moi}
\section*{Trip 3}\glsentrydesc{trip3}\\\ampersandtrip{trip3}{You \&\ me}
\section*{Trip 4}\glsentrydesc{trip4}\\\ampersandtrip{trip4}{Toi {\&} moi}

\printglossary
\end{document}
% arara: xelatex
% arara: makeglossaries
% arara: xelatex

It sounds silly, but I need it. Thanks!

  • 1
    it is probably simpler to input the ampersand as \& than to try to make it temporarily into an ordinary character. since that is a non-letter "control symbol", it won't gobble the space that follows in the input, so if you want a space there, you can input it without doing anything special. – barbara beeton Jun 27 '16 at 20:26
  • @barbarabeeton thanks for your comment. I have some homemade programs who imports texts from my body to glossaries description, & after fly again to another site of my body with \glsentrydesc. So, through these trips, spaces politic after \& are different. Ok, I edit my post for explain this necessity. – Zouib Jun 27 '16 at 22:11
  • 2
    One problem here is that by defining your entries in the document, on the next run the definitions will occur at \begin{document} when the .glsdefs file is read in, so the change in catcode comes too late for those entries. – Nicola Talbot Jun 27 '16 at 22:48
  • 1
    I'm not sure why you don't set the category code to 12, instead of 11. – egreg Jun 27 '16 at 23:04
  • @egreg excellent observation ! It saves the spaces problem :) – Zouib Jun 27 '16 at 23:13
3

Use \catcode`&=12, not 11 and use \makeampletter before defining the glossary entries.

\documentclass{scrbook} 

\newcommand\makeampletter{\catcode`\&=12\relax}
\newcommand\ampersandtrip[2]{%
  \newglossaryentry{#1}{
    name=#1,
    type=main,
    description={#2},
  }%
  #2\footnote{\gls{#1}}%
}

\usepackage{glossaries}
\makeglossaries

\makeampletter
\newglossaryentry{and}{name=and,description={I want to use my &!}}% \&
\newglossaryentry{et}{name=et,description={Je veux utiliser mon & !}}% \&

\begin{document}
\gls{and} & \gls{et}

\section*{Trip 1}

\glsentrydesc{trip1}
\ampersandtrip{trip1}{You & me}

\section*{Trip 2}

\glsentrydesc{trip2}
\ampersandtrip{trip2}{Toi &  moi}

\section*{Trip 3}

\glsentrydesc{trip3}
\ampersandtrip{trip3}{You \& me}

\section*{Trip 4}

\glsentrydesc{trip4}
\ampersandtrip{trip4}{Toi \& moi}

\printglossary
\end{document}

% arara: xelatex
% arara: makeglossaries
% arara: xelatex

enter image description here

  • 1
    This is literally the real life case of xkcd.com/1172 – percusse Jun 27 '16 at 23:43
  • What's the way to undo \makeampletter? That is, I think I'm asking, what should be the definition of \makeampother? – Quuxplusone Feb 28 '17 at 23:01
  • @Quuxplusone \newcommand{\makeampamp}{\catcode`\&=4\relax} – egreg Feb 28 '17 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.