Managing images
Switching between high-resolution and low-resolution versions of Images
So far, while specifying the image filename in the \includegraphics command, we have omitted file extensions. However, that is not necessary, though it is often useful. If the file extension is omitted, LaTeX will search for any supported image format in that directory, and will search for various extensions in the default order (which can be modified).
This is useful in switching between development and production environments. In a development environment (when the article/report/book is being developed), it is desirable to use low-resolution versions of images (typically in .png format) for fast compilation of the preview. In the production environment (when the final version of the article/report/book in development is produced), it is desirable to include the high-resolution version of the images.
This is accomplished by
- Not specifying the file extension in the \includegraphics command, and
- Specifying the desired extension in the preamble.
Thus, if we have two versions of an image, venndiagram.pdf (high-resolution) and venndiagram.png (low-resolution), then we can include the following line in the preamble to use the .png version while developing the report -
\DeclareGraphicsExtensions{.png,.pdf}
The command above will ensure that if two files are encountered with the same basename but different extensions (for example venndiagram.pdf and venndiagram.png), then the .png version will be used first, and in its absence the .pdf version will be used (low-resolution versions might not have been generated for some of the images).
Once the report has been developed, to use the high-resolution .pdf version, we can change the line in the preamble specifying the extension search order to -
\DeclareGraphicsExtensions{.pdf,.png}
Converting High-Resolution Images to Low-Resolution Automatically
Improving on the technique described in the last section, we can also instruct LaTeX to generate low-resolution .png versions of images on the fly during the LaTeX run if there is a PDF that has not been converted to PNG yet. To achieve that, we can include the following in the preamble after \usepackage{graphicx} -
\usepackage{epstopdf}
\epstopdfDeclareGraphicsRule{.pdf}{png}{.png}{convert #1 \OutputFile}
\DeclareGraphicsExtensions{.png,.pdf}
If venndiagram2.pdf exists but not venndiagram2.png, the file venndiagram2-pdf-converted-to.png will be created and loaded in its place. The command convert #1 is responsible for the conversion and additional parameters may be passed between convert and #1. For example - convert -density 100 #1.
Important Notes:
- For the automatic conversion to work, we need to call pdflatex with the --shell-escape option.
- For the final production version, we should comment out the \epstopdfDeclareGraphicsRule, so that only high-resolution PDF files should be loaded. We'll also need to change the order of precedence for extensions in the lines below.
Managing the folderpath to images
It may be useful to arrange all the images inside a directory-structure
- when a document uses a lot of images, or
- when we want to use the same image in multiple documents.
In such a case, we can tell LaTeX where to look for images using the command \graphicspath, which takes one argument specifying the additional paths we want to be searched when the \includegraphics command is used. Here are some examples:
\graphicspath{ {/home/mike/images/} }
\graphicspath{ {first_folder/}{second_folder/}{third_folder/} }
\graphicspath{ {./images/} }
\graphicspath{ {c:\mypict~1\images} }
\graphicspath{ {c:/mypict~1/images/} } % works with Windows OS
Notes
- Trailing / is required in the folder paths specified
- { {first_folder/}{second_folder/}{third_folder/} } is one argument, not three.
- In the fourth and fifth examples above, the "safe" (MS-DOS) form of the Windows MyPictures folder is used (because spaces in file path may create problem).
In the third example shown above, there should be a directory named "images" in the same directory as the main tex file. This is called RELATIVE addressing (the first, fourth and fifth example represent ABSOLUTE addressing). For more details, please refer to http://www.ctan.org/tex-archive/macros/latex/required/graphics/grfguide.pdf .
Using ABSOLUTE paths makes the file less portable between different systems (imagine having to recreate the same folder structure in all work-stations). Whenever possible, the use of RELATIVE addressing is recommended, particularly when the images are contained in a directory under the current directory. In particular, use only RELATIVE addressing in Overleaf projects.
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Debugging Compilation timeout errors
- How-to guides
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Fractions and Binomials
- Aligning Equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management in LaTeX
- Bibliography management with biblatex
- Biblatex bibliography styles
- Biblatex citation styles
- Bibliography management with natbib
- Natbib bibliography styles
- Natbib citation styles
- Bibliography management with bibtex
- Bibtex bibliography styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections and equations
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typing exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class
- Tips