0

I am using tikz plot in a LuaLatex paper. For a presentation, I would like to use the same plots in power point. Theoretically, I could add them as pdf object. The quality is quite bad though. Thus, I would like to export them as png. I found several code examples which should work. But I can't get them to work. They just output the pdf, no png.

I already tried following threads/ code snips.

https://tex.stackexchange.com/questions/40516/externalization-to-other-format-makefile-add-new-rules-to-the-makefile/40795#40795

https://www.latex4technics.com/?note=3p2n http://users.cecs.anu.edu.au/~rod/resources/p-tikz-external-png.html

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
%\tikzexternalize[mode=list and make]

\tikzset{
    png export/.style={
        % First we call ImageMagick; change settings to requirements
        external/system call/.add={}{; convert -density 300 -transparent white "\image.pdf" "\image.png"},
        % Now we force the PNG figure to be used instead of the PDF
        /pgf/images/external info,
        /pgf/images/include external/.code={
            \includegraphics[width=\pgfexternalwidth,height=\pgfexternalheight]{##1.png}
        },
    }
}

\begin{document}

{
% Here we specify the figure will be converted and inserted as PNG
\tikzset{png export}
\begin{tikzpicture}
    \draw (0,0) circle (1) ;
\end{tikzpicture}
}

% This figure will be inserted as PDF
\begin{tikzpicture}
    \draw (0,0) circle (1) ;
\end{tikzpicture}
\end{document}

I have checked the convert -version

Version: ImageMagick 7.0.8-49 Q16 x64 2019-06-08
http://www.imagemagick.org                                            
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC             
License: http://www.imagemagick.org/script/license.php                
Visual C++: 180040629                                                 
Features: Cipher DPC Modules OpenMP(2.0)                              
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2
jpeg lcms lqr    lzma openexr pangocairo png ps raw rsvg tiff webp xml
zlib   ```

If I check where convert I get

C:\Program Files\ImageMagick-7.0.8-Q16\convert.exe                    
C:\Windows\System32\convert.exe```

It seems suspicious to me to have two convert from different locations.

EDIT: This is now changed. I can call the convert.exe ether as imconvert or as magick. This works from console. It does not work from latex (texmaker) though.

Expected is a png and pdf output. Actual is a pdf output.

1 Answers1

1

As mentioned in some comments, the commands in external/system call/.add differ if using Windows: multiple commands are separated with & instead of ; on Linux. Also, to avoid confusion with the system tool convert, use magick.exe instead:

\tikzset{
    png export/.style={
        % First we call ImageMagick; change settings to requirements
        external/system call/.add={}{& magick.exe -density 300 "\image.pdf" "\image.png"},
        % Now we force the PNG figure to be used instead of the PDF
        /pgf/images/external info,
        /pgf/images/include external/.code={
            \includegraphics[width=\pgfexternalwidth,height=\pgfexternalheight]{##1.png}
        },
    }
}

For the exact same use case of exporting images (and even beamer animation steps) for PowerPoint, you can actually let LaTeX use the cached PDFs as normal and simply export the PNGs additionally, if needed with white instead of transparent background:

\tikzset{external/system call/.add={}{& magick.exe -density 300 "\image.pdf" -alpha remove "\image.png"}}

Note that \uncover in beamer might need \begin{frame}<1-n>, where n is your desired number of animation steps. \only might break node references and may cause filename conflicts, which can be solved by appending the overlay number. The latter can be combined with selective export of named figures only.

F1iX
  • 823
  • 6
  • 12