I'm writing a report on a programming project in LaTeX and need to insert some images. I created images using a Finite Element program Freefem++, and saved the results in image files. I've tried png, jpeg, eps, and ps, but would like to use jpg, and none of them work so far. I've searched all over the internet, and it seems like my code should work, so I'm not sure what I'm missing.





The domain considered will be



I've tried with the file in a folder images and in the same folder as the doc, I've tried with and without the file extension, with and without [pdftex] and \DeclareGraphicsExtensions, etc. It compiles with pdflatex and gives no errors, exit code 1, then when I try to view the pdf it says it doesn't exist, and asks if I've compiled the source code. If I compile with pdftex, it just creates a blank first page. I've tried everything I can think of, I don't know what I'm missing. Perhaps a package I need to install on my computer? Or just a stupid mistake in the code? Does anyone see my error? Thanks in advance!

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Corentin Mar 18 '14 at 18:41
  • What happens if you try to open the pdf using another application (e.g. Adobe Reader)? Also, what happens if you compile using pdflatex from the command line? – Ian Thompson Mar 18 '14 at 20:12
  • It doesn't even create a pdf file to open when I compile it. I haven't tried compiling from the command line, I'll give that a try. – JKH Mar 18 '14 at 20:26
  • I get this error in terminal: !pdfTeX error: pdflatex (file ./domain.jpg): reading JPEG image failed (no JPEG header found) ==> Fatal error occurred, no output PDF file produced! – JKH Mar 18 '14 at 20:31
  • 2
    As the other comments say, your image isn't being understood for some reason. Try leaving out the extension, check (using an image viewer) that the image is there, on Linux/MacOS the file(1) command should tell you what the image file really contains (perhaps some tool-specific format, or some different format than you think?). – vonbrand Mar 19 '14 at 0:48

The problem: apparently Freefem++ creates .jpg, .png, etc. images that are not readable by LaTeX. Thanks to the comments above telling me it was a problem with the image, I decided to try converting it to .jpeg (other formats probably would have worked as well, but I wanted jpg). To do this, I installed the ImageMagick package from terminal in linux, then used the convert command to create domain.jpeg:

$ convert domain.JPG domain.jpeg

This made the image usable, after that it was just formatting to get it to look right.

I stumbled on the same error with pandoc when trying to convert epub to pdf :

[macfarlane@boulder]:(~/Documents)$ pandoc -s -t latex --toc --chapters \
    --latex-engine=lualatex $BOOK.epub -o $BOOK.pdf
!LuaTeX error (file /tmp/tex2pdf.23440/3f21bef8dd2877aad72f5cddbf00284ca88fa0e7
.jpg): reading JPEG image failed (no marker found)
 ==> Fatal error occurred, no output PDF file produced!

pandoc: Error producing PDF

Here's a workaround. Check to see if a tex file can be produced :

[macfarlane@boulder]:(~/Documents)$ pandoc \
    -s -t latex \
    --toc --chapters \
    --latex-engine=lualatex $BOOK.epub -o $BOOK.tex

Extract images and other media contained in the epub container to the path DIR, creating it if necessary, and adjust the images references in the [LaTeX] document so they point to the extracted files, with the option --extract-media= DIR . Select the current directory which also contains the ePub file. Add --extract-media=. which means extract in the current directory, which is also $HOME/Documents

[macfarlane@boulder]:(~)$ cd Documents
[macfarlane@boulder]:(~/Documents)$ pandoc \
    -s -t latex \
    --toc --chapters \
    --latex-engine=lualatex \
    --extract-media=. $BOOK.epub -o $BOOK.tex
pandoc: extracting ./images/9781501144158.jpg
pandoc: extracting ./images/com-01.jpg
pandoc: extracting ./images/f0003-01.jpg
pandoc: extracting ./images/f0005-01.jpg
[ ----- extract-media logging shortened ---- ]
pandoc: extracting ./images/f0177-01.jpg
pandoc: extracting ./images/f0187-01.jpg
pandoc: extracting ./images/logo.jpg
pandoc: extracting ./images/logo1.jpg
pandoc: extracting ./images/title.jpg

Repeal the extracted .jpg images by creating new LaTeX compatible JPEG images with the `convert' utility (from the imagemagick program suite)

[macfarlane@boulder]:(~/Documents)$ cd images
[macfarlane@boulder]:(~/Documents/images)$ convert logo1.jpg logo1.jpeg 

and Replace the previously with pandoc extracted .jpg images with the newly created .jpeg images :

[macfarlane@boulder]:(~/Documents/images)$ mv logo1.jpeg logo1.jpg 

One can do this with a single for loop on the commandline :

[macfarlane@boulder]:(~/Documents)$ cd images/
[macfarlane@boulder]:(~/Documents/images)$ for i in *.jpg; do convert $i `echo $i | sed 's/jpg/jpeg/'`; done
[macfarlane@boulder]:(~/Documents/images)$ rm -f *.jpg
[macfarlane@boulder]:(~/Documents/images)$ for i in *.jpeg; do mv $i `echo $i | sed 's/jpeg/jpg/'`; done 
[macfarlane@boulder]:(~/Documents/images)$ cd ..

Run the first commandline again, but this time have the LuaTeX engine seek for its \includegraphics in the same directory as where the ePub images were extracted earlier ( --data-dir=DIRECTORY Specify the user data directory to search for pandoc data files. If this option is not specified, the default user data directory will be used. This is, in Unix: $HOME/.pandoc ) by adding the option --data-dir=. :

[macfarlane@boulder]:(~/Documents)$ pandoc \
    -s -t latex \
    --toc --chapters \
    --latex-engine=lualatex \
    --data-dir=. $BOOK.epub -o $BOOK.pdf
  • 2
    Welcome to TeX.SX! Please shorten this to the necessary details and then explain what you did. – TeXnician May 16 '17 at 5:41

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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