2

Nothing's wrong with the PNG as far as I'm aware, but I'm getting some wacky behavior from it (MWE below). The problem goes away when I remove -transparent white from the ImageMagick options.

MWE

% arara: xelatex: {shell: yes}
\begin{filecontents*}{heart.svg}
<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
  <g transform="matrix(26.37104, 0, 0, 24.680786, 232.422821, 233.229111)" style="fill: rgb(223, 0, 0); fill-opacity: 1;">
    <path style="fill:#df0000;fill-opacity:1" d="M 3.676,-9 C 0.433,-9 0,-5.523 0,-5.523 0,-5.523 -0.433,-9 -3.676,-9 -5.946,-9 -8,-7.441 -8,-4.5 -8,-0.614 -1.4208493,3.2938141 0,9 1.35201,3.2985969 8,-0.614 8,-4.5 8,-7.441 5.946,-9 3.676,-9 z"/>
  </g>
</svg>
\end{filecontents*}
\immediate\write18{convert -units PixelsPerInch -size 2000x2000 heart.svg -density 600 -trim -transparent white heart.png}
\documentclass{article}
\usepackage{graphicx}

\newcommand\CHeart[1][]{\includegraphics[width=\linewidth,#1]{heart.png}}

\begin{document}
\CHeart
\end{document}

Output: (blank pdf sometimes, other times…)

output

Version: ImageMagick 6.9.6-7 Q16 x86_64 2016-12-07 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules 
Delegates (built-in): bzlib cairo fontconfig freetype jng jpeg ltdl lzma png rsvg tiff xml zlib

Using -background none before the SVG (instead of -transparent white before the PNG) gets me this lovely 'modern art':

output

closed as off-topic by Sean Allred, Maarten Dhondt, Stefan Pinnow, Jesse, Mico Dec 9 '16 at 6:56

  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Some checks: heart.svg has the same contents as in the TeX source. heart.png is correctly converted, checked by file date and image viewer. The correct heart.png is found and included by LaTeX, checked by inspecting the .log file. – Heiko Oberdiek Dec 9 '16 at 4:21
  • I wonder: could this be similar to Why can't XeTeX handle this dank meme?? – Sean Allred Dec 9 '16 at 4:22
  • I doubt it, neither you have reported an error message nor it is a JPEG file. Also, XeTeX is not able to invent a second heart. I expect the error at an earlier stage, see my previous comment. – Heiko Oberdiek Dec 9 '16 at 4:35
  • 4
    I'm voting to close this question as off-topic because this seems to be a bug with OS X's Preview application – it works fine when I use Adobe Reader. – Sean Allred Dec 9 '16 at 5:32
0

Too long for a comment.

I do get the expected normal heart with transparent background with option -transparent white or a white background with -background none. Compiler: pdflatex -shell-escape and xelatex -shell-escape

Version of ImageMagick: 6.9.5-7 Q16 x86_64 2016-08-27

Version of XeTeX: 3.14159265-2.6-0.99996 (TeX Live 2016)

Transparent background

\RequirePackage{filecontents}% overwriting environment "filecontents"
\begin{filecontents*}{heart.svg}
<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
  <g transform="matrix(26.37104, 0, 0, 24.680786, 232.422821, 233.229111)" style
    <path style="fill:#df0000;fill-opacity:1" d="M 3.676,-9 C 0.433,-9 0,-5.523
  </g>
</svg>
\end{filecontents*}
\immediate\write18{convert -units PixelsPerInch -size 2000x2000 heart.svg -densi
%\immediate\write18{convert -units PixelsPerInch -size 2000x2000 heart.svg -dens
\documentclass{article}
\usepackage{graphicx}
\usepackage{color}

\newcommand\CHeart[1][]{\includegraphics[width=\linewidth,#1]{heart.png}}

\begin{document}
\pagecolor{yellow}
\noindent
\CHeart
\end{document}

Result with transparent background

White background

\RequirePackage{filecontents}% overwriting environment "filecontents"
\begin{filecontents*}{heart.svg}
<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
  <g transform="matrix(26.37104, 0, 0, 24.680786, 232.422821, 233.229111)" style
    <path style="fill:#df0000;fill-opacity:1" d="M 3.676,-9 C 0.433,-9 0,-5.523
  </g>
</svg>
\end{filecontents*}
%\immediate\write18{convert -units PixelsPerInch -size 2000x2000 heart.svg -dens
\immediate\write18{convert -units PixelsPerInch -size 2000x2000 heart.svg -densi
\documentclass{article}
\usepackage{graphicx}
\usepackage{color}

\newcommand\CHeart[2][]{\includegraphics[width=\linewidth,#1]{heart.png}}

\begin{document}
\pagecolor{yellow}
\noindent
\CHeart
\end{document}

Result with white background

The standard environment filecontents does not overwrite the file. If the contents of heart.svg changes, the file must be deleted first to get the new version on the next compile run.

The example uses package filecontents which always overwrites the files.

\pagecolor{yellow} is used to show the different background types.

TikZ version

The path description of the SVG file can directly be used in TikZ to get a vector graphics without external image file:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{svg.path}
\usepackage{xcolor}
\usepackage{graphicx}
\definecolor{heartred}{RGB}{223, 0, 0}
\begin{document}
\pagecolor{yellow}
\noindent
\resizebox{\linewidth}{!}{%
  \tikz\fill[heartred, yscale=-1] svg {
    M 3.676,-9 C 0.433,-9 0,-5.523 0,-5.523 0,-5.523 -0.433,-9 -3.676,
    -9 -5.946,-9 -8,-7.441 -8,-4.5 -8,-0.614 -1.4208493,3.2938141 0,
    9 1.35201,3.2985969 8,-0.614 8,-4.5 8,-7.441 5.946,-9 3.676,-9 z
  };%
}
\end{document}
  • Do you get different behavior with xelatex, perhaps? – Sean Allred Dec 9 '16 at 4:10
  • @SeanAllred I get the same behavior with xelatex -shell-escape. – Heiko Oberdiek Dec 9 '16 at 4:12
  • XeTeX 3.14159265-2.6-0.99996 (TeX Live 2016)? – Sean Allred Dec 9 '16 at 4:14
  • @SeanAllred The version of XeTeX is the same. – Heiko Oberdiek Dec 9 '16 at 4:15

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