# Beamer equation error

I am having some problems with my recent Beamer presentation, namely with equations.

I would like to typeset the phrase $$\sum_{i=1}^{n}i=\frac{n(n+1)}{2}$$ in a typewriter font inside an equation, to show the syntax of LaTeX equations for a presentation that I am making.

However, I am getting vague errors when I compile the following MWE using XeLaTeX:

\documentclass[14pt]{beamer}
\usetheme{metropolis}

\usepackage{amsmath, amstext}

\begin{document}
\begin{frame}[fragile]{Frame}
\begin{equation*}
\mathtt{\$\$\\sum\_\{i=1\}\;\widehat{}\;\{n\}i=\\frac\{n(n+1)\}\{2\}\$\$}
\end{equation*}
\end{frame}
\end{document}

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.3 ...idehat{}\;\{n\}i=\\frac\{n(n+1)\}\{2\}\$\$}

?


I also tried the verbatim environment, which works when replacing \mathtt{...} with \verb|$$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$$|, but fails when I attempt to animate it:

\documentclass[14pt]{beamer}
\usetheme{metropolis}

\usepackage{amsmath, amstext}

\begin{document}
\begin{frame}[fragile]{Frame}
\onslide<+->{
\begin{equation*}
\verb|$$\sum_{i=1}^{n}i=\frac{n(n+1)}{2}$$|
\end{equation*}}
\end{frame}
\end{document}

! Missing $inserted. <inserted text>$
l.5     \end{equation*}}

?


Any help would be much appreciated!

• unrelated to the problem, but if you want to show the latex syntax of equations, don't show it with $$...$$ (Why is $…$ preferable to $$?) – user36296 Mar 21 '19 at 20:01 • I am using $$...$$, because the presentation is about Jekyll-based website where the equations are rendered using KaTeX, and the setup I am using requires this syntax. – Tomáš Sláma Mar 21 '19 at 20:06 • OK, that make sense. Back to the question: there is one point which I don't understand: why do you want to put this inside an unnumbered equations? Why not put it in some verbatim or listings environment instead? – user36296 Mar 21 '19 at 20:21 • You are right, I should not have made the equation unnumbered. Thanks for the advice! – Tomáš Sláma Mar 21 '19 at 21:13 • \\ does not produce a backslash. – egreg Mar 21 '19 at 22:19 ## 1 Answer The second part of my question can be solved by removing the compound brackets after \onslide<+->: \documentclass[14pt]{beamer} \usetheme{metropolis} \usepackage{amsmath, amstext} \begin{document} \begin{frame}[fragile]{Frame} \onslide<+-> \begin{equation*} \verb|$$\sum_{i=1}^{n}i=\frac{n(n+1)}{2}|
\end{equation*}
\end{frame}
\end{document}