3

When I write the following code, it works.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{makeidx}
\makeindex
\newcommand{\p}{\raisebox{2pt}{$\mathfrak{p}$}}

\begin{document}

$\p(E)$\index{$\p(E)$}

\printindex
\end{document}

But what I need is this:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{makeidx}
\makeindex
\newcommand{\p}{\raisebox{2pt}{$\mathfrak{p}$}}

\newcommand{\idxx}[1]{$#1$\index{$#1$}}

\begin{document}

\idxx{\p(E)}

\printindex
\end{document}

But it fails. Why? How can I fix it?

  • \DeclareRobustCommand{\p}{\raisebox{2pt}{$\mathfrak{p}$}} – Gonzalo Medina Mar 1 '14 at 19:09
  • for situations like this, i'd recommend using a sort field for the index; i'm sure that "\raisebox" will not sort into any useful order by itself. – barbara beeton Mar 1 '14 at 19:23
2

Either you \protect the \p command inside \index, or better yet, use \DeclareRobustCommand in the definition:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{makeidx}
\makeindex
\DeclareRobustCommand{\p}{\raisebox{2pt}{$\mathfrak{p}$}}

\newcommand{\idxx}[1]{$#1$\index{$#1$}}

\begin{document}

\idxx{\p(E)}

\printindex
\end{document}
2
\newcommand\p{\protect\raisebox{2pt}{$\mathfrak{p}$}}

However, in general it is not a good idea to define macros with a name of a single character. There are some internal ones predefined.

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.