0

I'm using LaTeX to create Anki flashcards, which are converted from .pdf to .png with imagemagick so that they can be used with Anki.

I wanted to highlight some inline code snippets in a flashcard with a blue or grey background, which I tried to implement in my LaTeX code in two ways, as shown by this example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{microtype}

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc} 
\usepackage{lmodern}

\usepackage[parfill]{parskip} % turns off indentation at beginning of new paragraphs and adds a little bit of (stretchable) space in between paragraphs.
\usepackage{mathtools}
\usepackage{textcomp}     % access \textquotesingle

% Grey background and typwriter font for inline code
% https://tex.stackexchange.com/questions/140166/making-inline-code-printing-pretty
\usepackage{tikz}
\newcommand\code[2][]{\!\!
    \tikz[baseline=(s.base)]{
        \node(s)[
            fill=blue!10,           % background color
            %draw=blue!50,          % border of box
            inner xsep =3pt,    % horizontal space between text and border
            inner ysep =0pt,    % vertical space between text and border
            text height=2ex,    % height of box
            text depth =1ex,    % depth of box
            #1                  % other options
        ]{\texttt{#2}};
    }\!\!
}

% Grey background and typwriter font for inline code version 2
\definecolor{codegray}{gray}{0.9}
\newcommand{\codex}[1]{\colorbox{codegray}{\texttt{#1}}}


\begin{document}
Assuming you are writing in English, use \code{\`{}\`{}quoted\textquotesingle\textquotesingle} to get the result ``quoted'' (or \code{\`{}quoted\textquotesingle} for `quoted'). Note that in some languages, babel uses the \code{"} character for various purposes not related to quotation marks, so it really is best to avoid it.

Assuming you are writing in English, use \codex{\`{}\`{}quoted\textquotesingle\textquotesingle} to get the result ``quoted'' (or \codex{\`{}quoted\textquotesingle} for `quoted'). Note that in some languages, babel uses the \codex{"} character for various purposes not related to quotation marks, so it really is best to avoid it.
\end{document}

This results in this .pdf file, viewed by my pdf-viewer and cropped with Windows Snipping Tool. However, after converting and cropping it with imagemagick, some newly added yellow and/or grey lines are present, as shown here.

The imagemagick command used is:

magick -density 288 tmp.pdf -trim tmp.png

So I'm wondering, why are differently colored lines added, and how can I prevent this from happening?

ksh
  • 3
  • 2
  • 1
    What is your Imagemagick version and platform? What do you get from `magick -version`? Is the PDF in RGB or CMYK colorspace? What are your versions of Ghostscript and libpng? Can you provide a link to your input PDF or one that shows the same issue? Likely it is an old version of Imagemagick or your Ghostscript or libpng. – fmw42 Apr 18 '18 at 16:40
  • I had Imagemagick ImageMagick 7.0.7-13 and Ghostscript 9.20 installed. Updating to Ghostscript 9.23 did the trick, thanks for your help! – ksh Apr 19 '18 at 09:15

0 Answers0