0

The previous version of Anki compiled this without any issue:

\begin{center}
\includegraphics[scale=0.4]{recursion_tree.eps}
\end{center}

After upgrading to 2.1, I am unable to compile the above code. I reported the issue ad anki.tenderapp.com and was told that Anki 2.1 uses pdflatex, which does not support including eps files out of the box. The developer also said my use case is too niche to bother with, so I have to resolve this myself. I have done a lot of googling, but have not been able to find a straightforward way to fix this. Is there a simple fix to make this code compile or do I have to find some other way to include images in my cards in a latex environment? I tried just adding pngs, but kept getting overfull errors. I'd prefer to not have to specify image size every time I want to include an image. The nice thing about the old Anki was that I never seem to get any errors about the size of the image. It 'just worked':

https://anki.tenderapp.com/discussions/ankidesktop/37150-anyone-else-suddenly-having-trouble-using-graphicx-with-latex-to-include-eps-images-on-a-card-after-upgrading

My system:

Mac OSX Catalina
TexLive 2019
I have dvipng installed

I get the following error message for the above latex code:

Error executing dvipng.
Generated file: /var/folders/3t/67vlbpbx73l1l1m5yj8plvhr0010zw/T/anki_temp/tmp.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(./tmp.tex
LaTeX2e <2019-10-01> patch level 3
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/10/25 v1.4k Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/stackengine/stackengine.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2019/texmf-dist/tex/generic/listofitems/listofitems.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/listofitems/listofitems.tex))
(/usr/local/texlive/2019/texmf-dist/tex/latex/tools/calc.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/mathtools/mathtools.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/mathtools/mhsetup.sty))
(/usr/local/texlive/2019/texmf-dist/tex/generic/systeme/systeme.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/xstring/xstring.tex))
(/usr/local/texlive/2019/texmf-dist/tex/generic/systeme/systeme.tex))
(/usr/local/texlive/2019/texmf-dist/tex/latex/braket/braket.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/jknapltx/mathrsfs.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/changepage/changepage.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/adjustbox/adjustbox.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/xkeyval/xkvutils.tex)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/adjustbox/adjcalc.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/adjustbox/trimclip.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-def/dvips.def)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/collectbox/collectbox.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/adjustbox/tc-dvips.def))
(/usr/local/texlive/2019/texmf-dist/tex/latex/ifoddpage/ifoddpage.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/varwidth/varwidth.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/clrscode3e/clrscode3e.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/makecell/makecell.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/tools/array.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/multirow/multirow.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/tools/tabularx.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3packages/xfrac/xfrac.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/expl3-code.tex
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/l3deprecation.def))
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3backend/l3backend-dvips.def))
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)
 (/usr/local/texlive/2019/texmf-dist/tex/latex/base/textcomp.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/ts1enc.def
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/ts1enc.dfu)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.st
y)) (/usr/local/texlive/2019/texmf-dist/tex/latex/units/units.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/units/nicefrac.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/iftex/ifpdf.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/iftex/iftex.sty))
(/usr/local/texlive/2019/texmf-dist/tex/generic/iftex/ifvtex.sty)
(/usr/local/texlive/2019/texmf-dist/tex/generic/iftex/ifxetex.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te
x
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-li
sts.tex))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def
(/usr/local/texlive/2019/texmf-dist/tex/latex/ms/everyshi.sty))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/pgf.revision.tex)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.c
ode.tex))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-dvips.de
f
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-p
ostscript.def)))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.
code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.
code.tex)) (/usr/local/texlive/2019/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-cfg/color.cfg))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex
)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.
tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic
.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigo
nometric.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.rando
m.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.compa
rison.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.
code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round
.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.
code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integ
erarithmetics.code.tex)))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex)
) (/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfint.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.co
de.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconst
ruct.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage
.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.co
de.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicst
ate.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransform
ations.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.cod
e.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.c
ode.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathproce
ssing.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.co
de.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.cod
e.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.cod
e.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal.
code.tex))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.co
de.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretranspare
ncy.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns.
code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/basiclayer/pgfcorerdf.code.
tex)))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.cod
e.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.
tex)
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-0-65.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-1-18.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/utilities/pgffor.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/utilities/pgfkeys.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex)
) (/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/math/pgfmath.sty
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgffor.code.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex)))
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.cod
e.tex
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/libraries/pgflibraryplothan
dlers.code.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/modules/pgfmodulematrix.cod
e.tex)
(/usr/local/texlive/2019/texmf-dist/tex/generic/pgf/frontendlayer/tikz/librarie
s/tikzlibrarytopaths.code.tex)))
(/usr/local/texlive/2019/texmf-dist/tex/latex/booktabs/booktabs.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/umsb.fd)
(/usr/local/texlive/2019/texmf-dist/tex/latex/jknapltx/ursfs.fd) (./tmp.aux)
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/ts1cmr.fd)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
ABD: EveryShipout initializing macros
Underfull \hbox (badness 10000) in paragraph at lines 26--27

</Users/sephilli/Pictures/recursion_tree.eps> [1] (./tmp.aux) )
(see the transcript file for additional information)
Output written on tmp.dvi (1 page, 14344 bytes).
Transcript written on tmp.log.

Card template:

[latex]

         {\scriptsize GENERAL KNOWLEDGE \newline}


         {\small 

         {{Answer}} }

         <br>
         \begin{flushright} {\scriptsize {{Subject}} } \end{flushright}


[/latex]

Card styling:

.card {
font-family: arial;
font-size: 10px;
text-align: center;
color: black;
background-color: white;
}
img {
width: auto;
height: auto;
max-height:1000px;
}

Header for the card options:

\documentclass[10pt,letterpaper]{article}
\usepackage{amssymb,stackengine,amsmath,mathtools,systeme,braket,amsfonts,mathrsfs,changepage,mathtools, adjustbox,clrscode3e,makecell,multirow,tabularx,xfrac,units}
\usepackage[letterpaper,pass]{geometry}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{booktabs}
\pagestyle{empty}
\setlength{\parindent}{0in}
\stackMath
\graphicspath{ {/Users/sephilli/Pictures/} }
\newsavebox\boxofmathplus 
\sbox{\boxofmathplus}{$+$}
\setcellgapes{1pt}
\newcommand{\spaceforemptycolumn}{\makebox[\wd\boxofmathplus]{\ }}
\newlength{\grsteplength}\setlength{\grsteplength}{1.5ex plus .1ex minus .1ex}
\newcommand{\grstep}[2][\relax]{\ensuremath{\mathrel{\hspace{\grsteplength}\mathop{\longrightarrow}\limits^{#2\mathstrut}_{\begin{subarray}{l} #1 \end{subarray}}\hspace{\grsteplength}}}}\newcommand{\repeatedgrstep}[2][\relax]{\hspace{-\grsteplength}\grstep[#1]{#2}}
\newenvironment{linsys}[2][m]{\setlength{\arraycolsep}{.1111em}\begin{array}[#1]{@{}*{#2}{rc}r@{}}}{\end{array}}
\newenvironment{amatrix}[1]{\left(\begin{array}{@{}*{#1}{c}|c@{}}}{\end{array}\right)}
\newenvironment{mat}[1][c]{\begin{pmatrix*}}{\end{pmatrix*}}
\newcommand{\colvec}[2][c]{\begin{mat}[#1] #2 \end{mat}}
\newcommand{\rowvec}[1]{\setlength{\arraycolsep}{3pt}(\begin{matrix} #1 \end{matrix})}

\begin{document} 

Footer for the card options:

\end{document}

Configuration for the Latex build process:

{
    "pngCommands": [
        [
            "latex",
            "-interaction=nonstopmode",
            "tmp.tex"
        ],
        [
            "dvipng",
            "-D",
            "200",
            "-T",
            "tight",
            "tmp.dvi",
            "-o",
            "tmp.png"
        ]
    ],
    "svgCommands": [
        [
            "latex",
            "-interaction=nonstopmode",
            "tmp.tex"
        ],
        [
            "dvisvgm",
            "--no-fonts",
            "-Z",
            "2",
            "tmp.dvi",
            "-o",
            "tmp.svg"
        ]
    ]
}
Selena
  • 195
  • your log shows that it ran without error and included the eps, but you used latex not pdflatex so then you need dvips to convert thedvi file to ps then ps2pdf to convert that to pdf. – David Carlisle Nov 26 '19 at 00:01
  • So, then.... pdflatex isn't being used? OK. So, how do I fix the build configuration to work like the old version of Anki --- that is, I can get my includegraphics line to compile without error. – Selena Nov 26 '19 at 01:41
  • sorry I have no idea about anki, but for pdflatex you should first run epstopdf on your eps file and then include the pdf file pdflatex can not include eps (it will in fact run the conversion in the background if you try to include eps but simpler to include pdf) – David Carlisle Nov 26 '19 at 07:51

1 Answers1

0

After letting this sit for a long time, I finally found the solution. Here is a working setup for getting Anki 2.1 to work with latex markup that includes eps images:

  1. Install the Edit laTex build process add on

  2. Use the following for the pngCommands stanza:

    "pngCommands": [
       [
           "pdflatex",
           "--shell-escape",
           "-interaction=nonstopmode",
           "tmp.tex",
           "tmp.pdf"
       ],
       [
           "/usr/local/bin/convert",
           "-density",
           "200",
           "-trim",
           "tmp.pdf",
           "tmp.png"
       ]
    ]
    
  3. Install imagemagick and ghostscript

  4. Add the epstopdf package to the header for the card types that use latex markup and which need to include eps images:

     \usepackage{epstopdf}
    

I didn't test using the imagemagick convert command for producing an svg image. I am sure with the above example, anyone who wants to do that can figure out how to do it.

pdflatex doesn't produce dvi images, so my original attempt, based on my setup for the older Anki version, wouldn't work for Anki 2.1 which uses pdflatex. The intermediate file is a pdf file. Therefore, instead of dvipng, I needed something like imagemagick to convert the intermediate file to a png image.

In order for pdflatex to handle the eps to pdf conversion, the epstopdf package was necessary.

When I got all this working, I also had trouble with Anki not knowing where Ghostscript is installed. When I tried to preview the cards with eps images, they would error out because Ghostscript couldn't be located. I posted a question plus the solution I found to that here:

epstopdf cannot open ghostscript

luki
  • 1,796
Selena
  • 195