Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
\DeclareRobustCommand{\p}{\raisebox{2pt}{$\mathfrak{p}$}} –  Gonzalo Medina Mar 1 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 at 19:23

2 Answers 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}
share|improve this answer
\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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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