1

I am using the Springer nature latex template: https://www.overleaf.com/latex/templates/springer-nature-latex-template/gsvvftmrppwq.

\usepackage{amsmath, amsfonts, dsfont}
\usepackage{blindtext}
\usepackage{xcolor}

\usepackage{mathtools}
\usepackage{comment}
\usepackage{amsthm}
\usepackage{algorithm, algpseudocode}
\usepackage{caption, subcaption}
\usepackage[export]{adjustbox}
\usepackage{multirow}
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage{xr}
\usepackage{subfiles}

\newcommand{\E}{\mathbb{E}}
\newcommand{\p}{\mathbb{P}}
\newcommand{\Reals}{\mathbb{R}}

Unfortunately, I am getting the the error message ./sn-article.tex:75: LaTeX Error: Command \p already defined. Or name \end... illegal, see p.192 of the manual.

However, if I call $\p$ or \p, I get ./sn-article.tex:193: Missing $ inserted. <inserted text> .

Thanks!

3
  • Refer to Short names for macros - TeX - LaTeX Stack Exchange. but that shows it should be undefined by default...
    – user202729
    Commented Jan 24, 2023 at 3:02
  • Off-topic: If \E is supposed to represent the expectations operator, it would be better to define it via \DeclareMathOperator{\E}{\mathbb{E}}. Here, I use "better" in the sense of improved spacing around the glyph that's generated by \mathbb{E}.
    – Mico
    Commented Jan 24, 2023 at 3:05
  • If you consult the error log closely, you'll see that it does not claim that \p is undefined. Instead, it says that \p (and its argument) must be executed in math mode.
    – Mico
    Commented Jan 24, 2023 at 4:31

1 Answer 1

1

A macro -- or, at least, a macro that's defined via \def, \newcommand, or friends -- can't be simultaneously defined and undefined.

If I make your code snippet minimally compilable by prefixing it with \documentclass[default]{sn-jnl} and affixing \begin{document} \show\p \end{document} to it, I get the following output (written to the screen and log file, but not to the pdf file):

> \p=macro:
#1->\mathrel {\ooalign {\hfil $\mapstochar \mkern 5mu$\hfil \cr $#1$}}.
l.23 \show\p

This macro takes one argument and should be used in math mode since its "outermost" constituent directive is \mathrel.

Aside: \p is not defined in the LaTeX kernel or in one of the standard LaTeX document classes (article, report, and book). Instead, \p is defined as part of the sn-jnl document class.

If you don't care about this macro and don't mind clobbering it -- warning: proceed at your own risk! -- you could simply replace

\newcommand{\p}{\mathbb{P}}

with

\renewcommand{\p}{\mathbb{P}}

However, clobbering existing macros is generally ill-advised. Do consider coming up with a name other than \p for the macro you intend to use in the body of your document.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .