46

I am interested in including a triangle with an exclamation point (unicode #9888: ⚠) in a tex document. I've looked in the usual places (detexify, etc.) and not found this symbol. The document should be compilable with pdflatex and the source should have ASCII encoding. I already have a tikz version that I like reasonably well, given by

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\newcommand{\warningsign}{\tikz[baseline=-.75ex] \node[shape=regular polygon, regular polygon sides=3, inner sep=0pt, draw, thick] {\textbf{!}};}
\begin{document}
\warningsign Warning
\end{document}

so I am also requiring that the answer be an actual character, or at least not done using graphics.

7 Answers7

43

The fourier package provides \warning:

\documentclass{article}

\usepackage{fourier}

\begin{document}

\warning

\end{document}

I sometimes find that some of the fourier commands conflict with other packages I use, so if I only want this symbol I do:

\documentclass{article}

\begin{document}

{\fontencoding{U}\fontfamily{futs}\selectfont\char 49\relax}

\end{document}

which is essentially what \warning does. This requires the futs font family which is provided with the fourier package, so the package must still be installed even though it's not actually being loaded.

If the futs font isn't available, the transcript will show the message:

LaTeX Font Warning: Font shape `U/futs/m/n' undefined
(Font)              using `U/cmr/m/n' instead on input line 5.

This means that the cmr font is being used instead, which has something else in the \char 49 slot.

N. Virgo
  • 4,289
  • 2
  • 26
  • 41
Nicola Talbot
  • 41,153
  • 1
    In the second example, note that you need to have the fourier package installed in your TeX Live distribution even though it is not explicitly loaded. Otherwise, you will just get a "B" instead of a warning triangle. – Resigned June 2023 May 10 '17 at 03:08
  • Thanks, @RadonRosborough. I was initially getting a "B". [at]NicolaTalbot could you add that to the answer as well? – axolotl Jun 08 '17 at 10:13
  • I get this error in a Beamer document on Arch Linux: "mktexpk: don't know how to create bitmap font for futr8r. mktexpk: perhaps futr8r is missing from the map file." Is there another package I have to install? – Matthias Braun Sep 25 '19 at 08:49
  • 3
    Be aware that the command is now called \warning. Also, character number has changed to 49. So for option two use {\fontencoding{U}\fontfamily{futs}\selectfont\char 49\relax}. – Isotope Mar 25 '22 at 15:58
32

A \warning symbol (previously \danger) is provided by the fourier package (see The Comprehensive LATEX Symbol List, table 475, page 177).

If you don't have the need for the complete fourier package, but you want to use that symbol, you can extract it and use in your document:

\newcommand*{\TakeFourierOrnament}[1]{{%
\fontencoding{U}\fontfamily{futs}\selectfont\char#1}}
\newcommand*{\danger}{\TakeFourierOrnament{66}}

MWE

\documentclass{article}

\newcommand{\TakeFourierOrnament}[1]{{% \fontencoding{U}\fontfamily{futs}\selectfont\char#1}} \newcommand{\danger}{\TakeFourierOrnament{66}}

\begin{document}

\danger

\end{document}

Output

enter image description here

karlkoeller
  • 124,410
  • 4
    In my installation of TeX Live 2022, this MWE produces a different output. It looks like the position of the symbol in the alphabet was changed at some point, nowadays it is 49 rather than 66... – Martin Hairer Jul 20 '22 at 10:43
  • I needed to use \TakeFourierOrnament{`1} (not 66). Whatever... – cis Mar 06 '23 at 16:51
30

A simple build assigned to the unicode symbol, so you can use or \Warning:

mWE

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{newunicodechar}

\newcommand\Warning{%
 \makebox[1.4em][c]{%
 \makebox[0pt][c]{\raisebox{.1em}{\small!}}%
 \makebox[0pt][c]{\color{red}\Large$\bigtriangleup$}}}%

\newunicodechar{⚠}{\Warning}

\begin{document}

    Do⚠not⚠put your finger

    on the power plug.

\end{document}
Fran
  • 80,769
  • Great! It's been a while since this answer, but I needed it today and it exactly suited me. Thanks a ton. – Giuseppe Negro May 24 '23 at 15:09
  • Same thing but bigger: \newcommand\Warning{% \makebox[1.4em][c]{% \makebox[0pt][c]{\raisebox{.2em}{!}}% \makebox[1pt][c]{\color{red}\LARGE$\bigtriangleup$}}}% – Raoul HATTERER Sep 08 '23 at 12:05
  • That's very good! The fourier package suggested in other answers messes up with some fonts. – Delio Feb 24 '24 at 08:54
25

Here, I choose to build my own by overlaying a black, tiny ! atop a red $\triangle$, and then scaling the result to a desired [optional] size

\documentclass{article}
\usepackage{stackengine}
\usepackage{scalerel}
\usepackage{xcolor}
\newcommand\dangersign[1][2ex]{%
  \renewcommand\stacktype{L}%
  \scaleto{\stackon[1.3pt]{\color{red}$\triangle$}{\tiny !}}{#1}%
}
\begin{document}
This is a danger sign 5ex tall: \dangersign[5ex]\par
Here is the default (2ex) size: \dangersign
\end{document}

Zoom of result, to clarify my response to Charles' comment.

enter image description here

If one prefers a bolder !, just make it \bfseries:

\documentclass{article}
\usepackage{stackengine}
\usepackage{scalerel}
\usepackage{xcolor}
\newcommand\dangersign[1][2ex]{%
  \renewcommand\stacktype{L}%
  \scaleto{\stackon[1.3pt]{\color{red}$\triangle$}{\tiny\bfseries !}}{#1}%
}
\begin{document}
This is a danger sign 5ex tall: \dangersign[5ex]\par
Here is the default (2ex) size: \dangersign
\end{document}

enter image description here

  • Perhaps it's my imagination, but the exclamation point in the small version looks slightly off-center. – Charles Staats Feb 10 '14 at 20:03
  • @CharlesStaats Sometimes, when glyphs are overlaid, inexact rendering will make them appear off center. Zooming in reveals a better approximation, and the printed result is accurate. Zooming the small symbol to 6400% reveals aligned glyphs. – Steven B. Segletes Feb 10 '14 at 20:05
  • A question about the stackrel package: why does it render the \danger symbol from the fourier package as a letter B? – Charles Staats Feb 11 '14 at 02:26
  • @CharlesStaats Do you mean scalerel package? I would note that scalerel macros process their argument in math mode, by default, and one must actually delimit them with $...$ to process in text mode. So my guess is that the symbol is being processed in the wrong mode. – Steven B. Segletes Feb 11 '14 at 02:33
  • Your guess seems to have been entirely correct. Thanks! – Charles Staats Feb 11 '14 at 04:29
14

When you use XeLaTeX or LuaLaTeX you can simply use the character as is:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{STIXGeneral}
\newcommand\warningsign{⚠}
\begin{document}
    \warningsign Warning
\end{document}

Of course the font must contain it. (STIX does.)

It looks like this:

Warning sign

Notice that it is more common to give unicode code points in hexadecimal, here U+26A0.

If you don’t want to have unusual characters in your source code, you can specify the warning sign by its code point:

\newcommand\warningsign{\symbol{"26A0}}

(Found at “How do I enter an arbitrary Unicode code point into my document?”)

bodo
  • 6,228
13

The package fontawesome provides the commands \faWarning (equiv., \faExclamationTriangle for the warning icon, which looks like this:

enter image description here

A minimal example would be:

\documentclass{article}
\usepackage{fontawesome}

\begin{document}

\faWarning\, Warning: This product contains peanuts, %
which might not be very suitable for certain individuals.

\end{document}

The fontawesome package might be new, but it provides a wide range of high-quality web icons, and that makes it pretty relevant tool in terms of modern typesetting and design.

0

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand\danger[1][]{%
\begin{tikzpicture}[baseline=-0.5ex, inner xsep=0pt,#1]
\node[]{$\triangle$};
\node[yshift=0.125ex, scale=0.45]{!};
\end{tikzpicture}\space}

A danger-sing \danger is shown here.

\huge A danger-sing \danger[red] is shown here. \end{document}

cis
  • 8,073
  • 1
  • 16
  • 45