1

I am compiling a very simple document, embedding one EPS image. Latex converts this image to PDF and the file shows up in the directory - so far, so good. However, then I get the error "Missing $ inserted" and the image does not show up in the document (although the document does get compiled). What could be the problem?

\documentclass{article}
\usepackage{graphicx}
\newcommand*\myphone{\vcenter{\hbox{\includegraphics{smartphone.eps}}}}

\begin{document}

Hello World! \myphone

\end{document}

and the relevant portion from the log file:

Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4

38.

Package grfext Info: Graphics extension search list:
(grfext) [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext)             \AppendGraphicsExtensions on input line 456.
)

! Missing $ inserted.

<inserted text> 

   $

l.8 Hello World! \myphone

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

LaTeX Font Info: External font `cmex10' loaded for size
(Font)           <7> on input line 8.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 8.
Package epstopdf Info: Source file: <smartphone.eps>
(epstopdf)                    date: 2018-08-15 09:42:54
(epstopdf)                    size: 5318 bytes
(epstopdf)             Output file: <smartphone-eps-converted-to.pdf>
(epstopdf)                    date: 2018-08-15 09:51:21
(epstopdf)                    size: 3698 bytes
(epstopdf)             Command: <epstopdf --outfile=smartphone-eps-converted-to
.pdf smartphone.eps>
(epstopdf)             \includegraphics on input line 8.
Package epstopdf Info: Output file is already uptodate.
<smartphone-eps-converted-to.pdf, id=1, 175.65625pt x 315.1775pt>
File: smartphone-eps-converted-to.pdf Graphic file (type pdf)
<use smartphone-eps-converted-to.pdf>
Package pdftex.def Info: smartphone-eps-converted-to.pdf  used on input line 8.

(pdftex.def)             Requested size: 175.6558pt x 315.17673pt.
! Missing $ inserted.
<inserted text> 
                $
l.9 

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
C.Carl
  • 728

2 Answers2

1

\vcenter is a (primitive) command which needs math mode. You normally shouldn't use it at the user level. Better use \raisebox to shift your graphic:

\documentclass{article}
\usepackage{graphicx}
\newcommand*\myphone{\raisebox{-0.5\height}{\includegraphics[width=5mm]{example-image-duck}}}

\begin{document}

Hello World! \myphone

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
1

You can use adjustbox for fine tuning the vertical alignment.

The right command depends on your EPS/PDF image.

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

\DeclareRobustCommand{\myphone}{\includegraphics{smartphone}}
\DeclareRobustCommand{\myphonec}{\includegraphics[valign=c]{smartphone}}
\DeclareRobustCommand{\myphoneC}{\includegraphics[valign=C]{smartphone}}

\begin{document}

Hello World! \myphone\ Hello World!

Hello World! \myphonec\ Hello World!

Hello World! \myphoneC\ Hello World!

\end{document}

enter image description here

egreg
  • 1,121,712