2

I'm writing a term paper using LaTeX that includes a number of figures created using external tools. These figures are available in both bitmap and vector formats. Ideally I'd like to use the vector versions, of course, but these are fairly chunky (up to 40 MiB apiece), and if I include these rather than the bitmap versions, the resulting PDF for the paper is well in excess of 100 MiB.

This isn't a problem per se. However, I have to submit the paper in both paper and electronic form (by email), and emailing such a large file could be an issue. I've therefore wondered if there is an easy (!) way of producing two versions of the paper, one for printing (using vector graphics) and one for emailing (a ,,web version´´, using bitmap graphics) from the same TeX file. The TeX file is already suitably prepared, I merely need to ,,flip a switch´´ to produce either version, but I cannot produce both at the same time, with different names.

I'd like to avoid using makefiles etc.; my workflow's based on TeXstudio on Windows, so something that's pure TeX (well, LaTeX is fine) would be best. I've looked at \input and \include, but I'm wondering if there's any tricks or Best Current Practices where ideally, I only need to run xelatex termpaper.tex or so and get both termpaper-web.pdf and termpaper-print.pdf.

I do apologize for the relatively open-ended question. Thanks in advance!

5

You could try something like this.

\newcommand{\printversion}[1]{
   \includegraphics[width=whatever]{#1.bmp}
}

\renewcommand{\printversion}[1]{
    \includegraphics[width=whatever]{#1.pdf}
}

Then wherever you wanted to include the file you would call \printversion{filename_without_extension} and it would print one of the two. Just comment out the \renewcommand if you want to use the bmp, or leave it in to use pdf.

You are going to need to convert the vector graphics from SVG to PDF. If you are willing to go down the rabbit whole you can install inkscape and use \usepackage{SVG} to automatically convert SVG to pdf, but the setup was kidna a pain. If you only have a few graphics id recommend just doing it manually with whatever tool you used to make the SVGs with in the first place.


Edit:

Looking into maybe a prettier solution, you could probably nest this into an if statement like

\newif\ifvectors%name of conditional is 'vectors' appended to 'if'

\vectorsfalse%the conditional 'vectors' to 'false' or 'true'

\ifvectors
   \def\printext{.pdf}
\else
   \def\printext{.bmp}
\fi

\newcommand{\printversion}[1]{
   \includegraphics[width=whatever]{#1\printext}
}
| improve this answer | |
  • 2
    Whoever downvoted, please leave a comment as to why you think this served a downvoted so that perhaps the OP can improve the answer and address your issue? – Peter Grill Sep 25 '19 at 17:03
  • 2
    I'd suggest defining \newcommand{\printversion}[2][]{\includegraphics[#1]{#2\printext}} so that one can use the key-val. Also make sure your lines are properly terminated with % (the downvote wasn't mine though). – Phelype Oleinik Sep 25 '19 at 17:39
  • @PhelypeOleinik Yes I always forget about the % termination. Also can you explain why there is a second empty [] needed in the command? – Bob Sep 25 '19 at 17:43
  • Ah I figured it out. It makes the #1 an optional [] part of of the \printversion[options]{filename_without_extention}. That is a very cool idea. – Bob Sep 25 '19 at 17:46
  • @Bob Yes, if you give a second [...]-delimited argument to \(re)newcommand then the command will have an optional argument and what's inside that [...] will be the default value of the optional argument. See here. – Phelype Oleinik Sep 25 '19 at 17:50

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