3

Deal all,

I have the following couple of new commands, using amsmath and relsize packages :

\newcommand*{\chiffraged}[2]{$\genfrac{}{}{0pt}{}{\mathlarger{#1}}{\mathlarger{#2}}$}
\newcommand*{\sixcinqbarre}{\chiffraged{6}{\cancel{5}}}

which allow me to display, in a regular text, a musical chord notation like this (chord C) : enter image description here

When I use my \sixcinqbarre in my text, no problem, everyting works (example in french, sorry):

     On trouvera tout naturellement l'écriture \textit{do ré}\quartesixte~\textit{mi}6
précédée du \textit{si}\sixcinqbarre .
     L'accord de passage est en général faible tandis que les deux accords de tonique sont
    placés sur les temps forts.
    L'accord sur la sensible est ainsi lui aussi en position faible. On a
    donc \textit{si do ré mi}. Nous en donnons un exemple.

gives:

enter image description here

When I use it in a title with no toc reference, like \subsection*{\sixcinqbarre}, idem, no problem. But when I use it in a regular title, like this \subsection{\sixcinqbarre}, I have the following error :

! Undefined control sequence.
\rs@makelargerchoice ...displaystyle \rs@mathatom
\m@th $}}{\displaystyle \l...
l.197 ...\sixcinqbarre ~avec la basse descendante}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

Does anyone have a clue about this?

Edit: After some tests, it seems that the use of the hyperref package is the cause of the error. Here is a code to test:

\documentclass[a4paper]{book}
\usepackage[]{hyperref}
\usepackage{cancel}
\usepackage{amsmath}
\usepackage{relsize}

\DeclareRobustCommand*{\chiffraged}[2]{$\protect\genfrac{}{}{0pt}{}{\protect\mathlarger{#1}}{\protect\mathlarger{#2}}$}
\DeclareRobustCommand*{\sixcinqbarre}{\chiffraged{6}{\cancel{5}}}

\begin{document}
\section{\sixcinqbarre}
\end{document}

Comment the \usepackage[]{hyperref}, and it works! However I would like to keep it...any idea?

  • Welcome to TeX.SX! You should do \DeclareRobustCommand*{\sixcinqbarre}{\chiffraged{6}{\cancel{5}}} and similarly for \chiffraged, if you plan to use the macros in a moving argument (sectional title or caption). – egreg Sep 19 '16 at 9:15
  • Thanks for your answer :) And sorry for the possible duplication... I tried what you suggested : to replace \newcommand* by \DeclareRobustCommand* in both commands, I still have the same error...idem if I replace \sixcinqbarre by \protect\sixcinqbarre in the title. Idem if I do both. Did I miss something? Maybe a package inclusion ? – jules Sep 19 '16 at 9:43
  • Up, does anyone can help me on this one? – jules Sep 20 '16 at 13:48
  • Please, edit your question adding a minimal example of code producing the issue. The question might be reopened, if a quick workaround cannot be found. – egreg Sep 20 '16 at 14:06
  • Thanks again for your answer. I added a bunch of code to test, with a new hint on the cause of the problem... – jules Sep 20 '16 at 15:03
3

The use of hyperref requires another level of protection:

\documentclass[a4paper]{book}
\usepackage{cancel}
\usepackage{amsmath}
\usepackage{relsize}
\usepackage[]{hyperref}
\usepackage{bookmark} % recommended

\DeclareRobustCommand*{\chiffraged}[2]{%
  $\genfrac{}{}{0pt}{}{\mathlarger{#1}}{\mathlarger{#2}}$%
}
\DeclareRobustCommand*{\sixcinqbarre}{\chiffraged{6}{\cancel{5}}}
% also protect the commands for the bookmarks
\pdfstringdefDisableCommands{%
  % provide an approximate representation for the bookmarks
  \renewcommand\chiffraged[2]{#1 #2}%
  \renewcommand\sixcinqbarre{6/5}%
}

\begin{document}

\section{\sixcinqbarre{} \chiffraged{6}{4}}

\end{document}

You may consider a different definition for \chiffraged:

\DeclareRobustCommand*{\chiffraged}[2]{%
  \begingroup\renewcommand{\arraystretch}{0}%
  \begin{tabular}{@{}c@{}}#1\\[1pt]#2\end{tabular}%
  \endgroup
}
|improve this answer|||||
  • Thanks ! Now it works like a charm. Why do you recommand to change \chiffraged ? – jules Sep 20 '16 at 22:01
  • @jules Well, I think that a generalized fraction is not the right tool. You might use a display style fraction, instead of using \mathlarger, though. – egreg Sep 20 '16 at 22:03
  • Yes I understand, I'll follow your advice! – jules Sep 20 '16 at 22:06
2

Special symbols are not allowed in pdf bookmarks. As hyperref generates these names from the section titles, you have to provide an alternative text \section{\texorpdfstring{\sixcinqbarre}{Bla}}

\documentclass[a4paper]{book}
\usepackage{cancel}
\usepackage{amsmath}
\usepackage{relsize}
\usepackage{hyperref}

\DeclareRobustCommand*{\chiffraged}[2]{$\protect\genfrac{}{}{0pt}{}{\protect\mathlarger{#1}}{\protect\mathlarger{#2}}$}
\DeclareRobustCommand*{\sixcinqbarre}{\chiffraged{6}{\cancel{5}}}

\begin{document}
\section{\texorpdfstring{\sixcinqbarre}{Bla}}
\end{document}

enter image description here

|improve this answer|||||

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.