0

我正在使用 LaTeX 创建 Anki 抽认卡,使用 imagemagick 将它们从 .pdf 转换为 .png,以便它们可以与 Anki 一起使用。

我想突出显示具有蓝色或灰色背景的抽认卡中的一些内联代码片段,我尝试以两种方式在我的 LaTeX 代码中实现,如下例所示:

\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}

这会生成这个.pdf 文件,由我的 pdf 查看器查看并使用 Windows 截图工具进行裁剪。但是,在使用 imagemagick 进行转换和裁剪后,会出现一些新添加的黄色和/或灰色线条,如下所示

使用的 imagemagick 命令是:

magick - 密度 288 tmp.pdf -trim tmp.png

所以我想知道,为什么要添加不同颜色的线条,如何防止这种情况发生?

4

0 回答 0