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.
  • 5
    \vcenter is a math command. – Ulrike Fischer Aug 15 '18 at 8:27
  • @UlrikeFischer Oh, I did not know that, I copied this code snippet from another answer on here. I deleted it, now it works, thanks! But how do I make sure the symbol is aligned with the text using a non-math command? – Anne Morbach Aug 15 '18 at 8:33
  • 1
    I would use something like \raisebox{-0.5\height}{...}. Adjust the factor so that it fits. – Ulrike Fischer Aug 15 '18 at 8:46
  • @UlrikeFischer Perfect, that does what I need. Thank you! – Anne Morbach Aug 15 '18 at 8:53
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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.