Missing $ inserted |

missingprogramtemplates

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

my equation is:

\documentclass[pdflatex,sn-mathphys]{sn-jnl}% Math and Physical Sciences Reference Style
\jyear{2021}%
\theoremstyle{thmstyleone}%
\newtheorem{theorem}{Theorem}%  meant for continuous numbers
\newtheorem{proposition}[theorem]{Proposition}% 
\theoremstyle{thmstyletwo}%
\newtheorem{example}{Example}%
\newtheorem{remark}{Remark}%
\theoremstyle{thmstylethree}%
\newtheorem{definition}{Definition}%
\raggedbottom
\begin{document}


\begin{equation}
J(A, B)=\frac{|A \cap B|}{|A \cup B|}
\end{equation}


\bibliography{sn-bibliography}% common bib file
\end{document}

The same problem with:

\begin{equation}
dh_{i}=\left|h_{t l}-h_{i}\right|
\end{equation}

it gives an error and doesn't show | in the equation.

Best Answer

For very mysterious reasons, the class loads program.sty, an obscure package that does several mysterious things and has essentially no documentation: one page with no examples; it tells to look into program-demo.tex, which is pretty uninformative as well.

On the other hand, the scanty documentation for the package tells users to use origbar instead of |.

You should complain with the editors and the maintainers of the class, because forcing users to deal with this package is really awful of them. By the way, the class also loads algpseudocode, which is much better than program. What I find most irritating is that the package redefines \( and \).

Anyway, you can solve your problem by using \lvert and \rvert which are actually better than the unadorned | to denote absolute value or cardinality. LaTeX also provides \vert as an alias.

\documentclass[pdflatex,sn-mathphys]{sn-jnl}% Math and Physical Sciences Reference Style

\jyear{2021}

\theoremstyle{thmstyleone}
\newtheorem{theorem}{Theorem}%  meant for continuous numbers
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{thmstyletwo}
\newtheorem{example}{Example}
\newtheorem{remark}{Remark}
\theoremstyle{thmstylethree}
\newtheorem{definition}{Definition}
\raggedbottom

\begin{document}

\begin{equation}
J(A, B)=\frac{\lvert A \cap B\rvert}{\lvert A \cup B\rvert}
\end{equation}


\bibliography{sn-bibliography}% common bib file

\end{document}

enter image description here

A more drastic step would be to undo the (wrong) settings made by program.sty.

\documentclass[pdflatex,sn-mathphys]{sn-jnl}% Math and Physical Sciences Reference Style
\jyear{2021}%
\theoremstyle{thmstyleone}%
\newtheorem{theorem}{Theorem}%  meant for continuous numbers
\newtheorem{proposition}[theorem]{Proposition}% 
\theoremstyle{thmstyletwo}%
\newtheorem{example}{Example}%
\newtheorem{remark}{Remark}%
\theoremstyle{thmstylethree}%
\newtheorem{definition}{Definition}%
\raggedbottom

%%% Undo the settings made by program.sty
\catcode`_=8 % _ is subscript
\catcode`|=12 % | is a normal character
\mathcode`;=\semicolon
\mathcode``=``
\makeatletter
\DeclareRobustCommand\({\relax\ifmmode\@badmath\else$\fi}
\DeclareRobustCommand\){\relax\ifmmode\ifinner$\else\@badmath\fi\else \@badmath\fi}
\makeatother
%%%

\begin{document}

\begin{equation}
J(A, B)=\frac{|A \cap B|}{|A \cup B|}
\end{equation}


\bibliography{sn-bibliography}% common bib file
\end{document}
Related Question