22

I tried to use the lightning symbol but when I use it together with equations it becomes an ''E'' Why is that?

\documentclass[11pt,a4paper,oneside]{report} 
\usepackage[pdftex]{graphicx} 
\usepackage[T1]{fontenc} 
\usepackage{fouriernc}
\usepackage{mathtools}
\usepackage{amsfonts,amsmath,amssymb,amsthm} 
\usepackage[a4paper, hmargin={3.5cm,3cm}, vmargin={2.5cm,2.5cm}]{geometry} %margin
\usepackage{multicol}
\usepackage{enumerate}
\usepackage{ marvosym }


\begin{document}
\Lightning
but when used in an equation environment it becomes ''E''
\begin{equation}
\Lambda\gamma \Lightning
\end{equation}
\end{document}

the output enter image description here

What can be done to use \Lightning in equations? Thank you

1

4 Answers 4

15

To instruct LaTeX to treat \Lightning as a text-mode rather than as a math-mode macro, you could type either

\mbox{\Lightning}

or (since you're already loading the amsmath package)

\text{\Lightning}

for all math-mode occurrences of this macro.


Addendum: As @egreg has pointed out in a comment, a key issue (bug?) is that the file marvosym.sty provides the instruction

\newcommand{\mvchr}[1]{{\mvs\char#1}}

This macro assumes (implicitly) that the symbols of the marvosym package will only ever be used in text mode. By redefining this macro via

\renewcommand{\mvchr}[1]{\mbox{\mvs\symbol{#1}}}

in the preamble (after loading the marvosym package, of course), the behavior of this macro is modified globally and it's no longer necessary to encase any of the many individual macros of the marvosym package in \mbox wrappers.

5
  • 5
    A different strategy could be \renewcommand{\mvchr}[1]{\mbox{\mvs\symbol{#1}}} (or \text instead of \mbox with amsmath). This is what \mvchr should do to begin with.
    – egreg
    Aug 29, 2014 at 9:01
  • The best way to do this is \textnormal{\Lightning}, or possibly \textup{\Lightning} if you want a bold version to show in headers. If you use \text while the surrounding text is an italicized theorem statement, it will also be italicized. If you use \mbox, the symbol won’t scale in a superscript or subscript.
    – Davislor
    Nov 14, 2020 at 20:38
  • @Davislor - Thanks. The \Lightning macro of the marvosym package doesn't appear to possess an italic or bold variant, let alone bold-italic, sans-serif, or small-caps variants. Hence, the recommendation to replace \text with either \textnormal or \textup doesn't affect the output of \Lightning. Am I maybe missing something?
    – Mico
    Nov 14, 2020 at 21:03
  • 1
    @Mico I think you’re right about marvosym, but if the package ever gets updated with more font faces, or the asker ever copies this code into a different document, it’d break unexpectedly.
    – Davislor
    Nov 14, 2020 at 21:05
  • @Davislor - Martin Vogel last updated the marvosym package more than nine years ago. Should he update his package along the lines you envisage, I would fervently hope that he'd have the good sense to incorporate the required safeguards into the package code. Knock on wood.
    – Mico
    Nov 14, 2020 at 21:16
24

Just in order to show some more ways to get a lightning symbol (the answer to your problem has been given in Micos answer and in the referenced questions in my comment):

% arara: lualatex

\documentclass{article}
\usepackage{mathtools}
\usepackage{marvosym}
\let\marvosymLightning\Lightning
\usepackage{wasysym}
\let\wasysymLightning\lightning
\usepackage{stmaryrd}
\let\stmaryrdLightning\lightning
\usepackage{ulsy}
\let\ulsyLightning\blitza
% just for the last two lines:
\usepackage{fontspec}

\begin{document}
\[\text{\marvosymLightning}\text{\wasysymLightning}\stmaryrdLightning\text{\ulsyLightning}\]
% Lua- or XeLaTeX needed for the following example:
Unicode symbol \texttt{U+26A1} "High Voltage" and  \texttt{U+2607} "Lightning"
\setmainfont{DejaVuSans.ttf}
\[\text{\symbol{"26A1}\symbol{"2607}}\]
\end{document}

If you comment out the last package and the last two lines in the document, you may compile with PDFLaTeX as well. I just wanted to show the two unicode symbols I found for lightnings and how you could access them.

enter image description here

Or you use the package fontawesome:

% arara: lualatex

\documentclass{article}
\usepackage{mathtools}
\usepackage{fontawesome}

\begin{document}
\[\text{\faBolt}\]
\end{document}

enter image description here

1
  • 2
    Beautiful. I did not know you could change their sizes and make them bold as well. Great tips. Thank you
    – user124471
    Aug 30, 2014 at 9:58
1
\usepackage{ stmaryrd }
\lightning
mathmode

\usepackage{ wasysym }
\lightning
textmode

\usepackage{ marvosym }
\Lightning
textmode
2
  • 1
    Can you provide a complete MWE for each of your suggestions?
    – azetina
    Nov 15, 2020 at 16:49
  • 1
    This entry was actually more helpful than the others as it's simple and it works. It could be improved by including a PDF for illustration, though.
    – Prof.Chaos
    Feb 4, 2021 at 0:57
1

A better way is to use \textup, not \text or \mbox.

\documentclass[11pt,a4paper,oneside]{report} 
\usepackage[T1]{fontenc} 
\usepackage{fouriernc}
\usepackage{mathtools}
\usepackage{amssymb,amsthm} 
\usepackage[a4paper, hmargin={3.5cm,3cm}, vmargin={2.5cm,2.5cm}]{geometry} %margin
\usepackage{ marvosym }

\newcommand\blitz{\textup{\Lightning}}

\begin{document}
\section*{The {\Lightning} Symbol in Math Mode is \(\blitz^{\blitz^\blitz}\)}'
\begin{equation*}
\Lambda\gamma \blitz_{\blitz_\blitz}
\end{equation*}
\end{document}

Marvosym sample

If you want to use it as an operator, additionally wrap it in \mathbin{\textup{\Lightning}} or \mathrel{\textup{\Lightning}}, etc. If you do not want the symbol to appear bold in bold headers, use \textnormal instead of \textup. (I don’t believe this does anything for marvosym, but it would for many other symbol fonts.)

If you use \text, the symbol will be formatter to match the surrounding text—for example, it will switch to italics if used in an italicized theorem statement. If you use \mbox, it will not scale in superscripts or subscripts.

In LuaLaTeX or XeLaTeX, you should use the ☇ (U+260 Lightning) or ⚡ (U+26A1 high voltage) Unicode symbols from a font that contains them, e.g.

\documentclass[11pt,a4paper,oneside]{report}
\tracinglostchars=2
\usepackage{mathtools}
\usepackage{amsthm} 
\usepackage{unicode-math}

\setmainfont{TeX Gyre Schola} % Clone of the New Century Schoolbook font used in fouriernc
\setmathfont{TeX Gyre Schola Math}
\newfontfamily\symbolfont{DejaVu Sans}[Scale=MatchUppercase]

\newcommand\textblitz{{\symbolfont\symbol{"26A1}}}
\newcommand\mathblitz{\textup{\textblitz}}

\usepackage[a4paper, hmargin={3.5cm,3cm}, vmargin={2.5cm,2.5cm}]{geometry} %margin

\begin{document}
\section*{The {\textblitz} Symbol in Math Mode is \(\mathblitz^{\mathblitz^\mathblitz}\) }
\[ \Lambda\gamma \mathblitz_{\mathblitz_\mathblitz}
\]
\end{document}

TeX Gyre Schola/DejaVu Sans sample

You must log in to answer this question.

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