3

Unfortunately I don't have enough reputation to comment on other questions asking the exact same thing but I wanted to repost the question because none of the other answers seemed to be helping me.

I am using Anki (2.1) to study for the MCAT and I customized my cards to look a particular way. I tried to use LaTeX since that's what Anki uses by default but my formulas are not appearing the way I want them to (different font, different color). I posted a previous question and the person who responded was able to give me a template for using either LaTeX and XeTeX (How do you change the font and font color in LaTeX (Anki)?) and I wanted to use XeTeX. I installed the "Edit latex build process" add-on and that allowed me to make the background transparent but trying to run XeTeX is giving me the error: "Have you installed latex and dvipng?"

I clearly have LaTeX (as well as Mactex) installed and I tried to reroute the command-line with the add-on to use XeTeX (similar to this: http://www.jasoncantarella.com/wordpress/anki-2-022latexmavericks-problems-and-solutions/), but I'm still getting the error.

The only thing I can think of is maybe I'm having the same problem as this redditor: https://www.reddit.com/r/Anki/comments/7t39mc/how_to_change_the_latex_compiler_anki_uses/.

The code for my preamble is:

\documentclass[12pt]{article}
\usepackage[paperwidth=5in, paperheight=3in]{geometry}
\usepackage[svgnames, Svgnames, HTML]{xcolor}
\usepackage{mathtools}
\usepackage{unicode-math}
\setmainfont{Anonymous Pro}[Scale = 1.0]
\setmonofont{Anonymous Pro}
\setmathfont{GFS Neohellenic Math}
\setmathfont[range=up]{Anonymous Pro}
\setmathfont[range=it]{Anonymous Pro Italic}
\setmathfont[range=bfup]{Anonymous Pro Bold}
\setmathfont[range=bfit]{Anonymous Pro Bold Italic}
\color{white}
\nopagecolor
\begin{document}

And the code for the add-on is:

{
    "pngCommands": [
        [
            "/Library/TeX/texbin/xelatex",
            "-interaction=nonstopmode",
            "tmp.tex"
        ],
        [
            "/Library/TeX/texbin/dvipng",
            "-D",
            "200",
            "-T",
            "tight",
            "tmp.dvi",
            "-o",
            "-bg",
            "Transparent",
            "tmp.png"
        ]
    ],
    "svgCommands": [
        [
            "/Library/TeX/texbin/xelatex",
            "-interaction=nonstopmode",
            "tmp.tex"
        ],
        [
            "/Library/TeX/texbin/dvisvgm",
            "--no-fonts",
            "-Z",
            "2",
            "tmp.dvi",
            "-o",
            "-bg",
            "Transparent",
            "tmp.svg"
        ]
    ]
}

I'm at a total loss here. Any help would be greatly appreciated!

6
  • 1
    I haven’t used Anki, unfortunately, but I upvoted in the hope someone who can answer your question sees it. Good luck! – Davislor Feb 2 '19 at 4:35
  • 1
    I don't use Anki either and therefore can't really help, but you should drop "-bg", "Transparent", from the call of dvisvgm. These are unknown parameters and will lead to a failure. – Martin Feb 3 '19 at 9:12
  • 1
    I have no knowledge of mac paths but the "Have you installed latex and dvipng/dvisvgm? " is a generic message to say something needed was not found in the expected system path. from jasoncantarella.com/wordpress/… we see 1) is dvipng in the correct location for the add-on thus "/Library/TeX/texbin/dvipng" shown above 2) latex (/ xelatex) & dvipng in some versions maybe in /usr/texbin or elsewhere on your default path ~~ Difference in needs was supposedly addressed by another anki add-on “Edit_LaTeX_and_dvipng_calls” plus other edits – user170109 Feb 3 '19 at 22:52
  • 1
    Also review "newest" question/answers by searching anki above e.g. tex.stackexchange.com/questions/271185/… and others note Anki builds in a temp directory/folder a file called tmp.tex alongside you will find half a dozen files including two trace logs the short one is latex_log.txt (which Anki feeds back to the user) also is the more useful tmp.log with more useful information from the tex compilation that you or we may find has clues – user170109 Feb 4 '19 at 2:53
  • @KJO I installed that add-on and I followed the instructions on that website but I still get errors. I also tried to look for tmp.tex and latex_log.txt under usr but I can't find either file either. – wuhoo Feb 4 '19 at 19:30
2

the Problem

My english is not good. Sorry about any misunderstanding, grammer error or hardness to understand this answer.

Warning: If you are new to TeX, command line and so on, this answer may not very detailed (for Anki users).

Well, you mentioned about "XeTeX". I suppose you mean "XeLaTeX".

XeLaTeX outputs xdv(or pdf) not dvi, so dvipng cannot work. (And the error massage, "Have you installed latex and dvipng?" is quite obscure. I get this error when setting the environment properly.)

I use this workflow:

tex --xelatex--> xdv --xelatex--> pdf --A Program--> png / svg

(latexmk can also be used.)

(I don't think it is an elegant way. Embed pdf in HTML directly is better.)

Use ghostscript

Workflow: tex --xelatex--> xdv --xelatex--> pdf --ghostscript--> png

TL;DR (Too Long; Don't Read)

  1. Setup ghostscript (Don't use the version in TeX Live, it seems to cannot be used in the command line (or I'm wrong).)
  2. Add ghostscript to PATH
  3. Setup add-on "Edit LaTeX build process"

In the add-on, "Edit LaTeX build process", json code is

{
  "pngCommands": [
    [
      "xelatex", 
      "-interaction=nonstopmode", 
      "tmp.tex"
    ],
    [
      "gswin32c", // Windows 32bit version 
      "-dNOPAUSE",
      "-sDEVICE=pngalpha",
      "-r300",
      "-dBATCH",
      "-dSAFER",
      "-sOutputFile=\"tmp.png\"",
      "tmp.pdf"
    ]
  ],
  "svgCommands": [ // I don't modify this.
    ["latex", "-interaction=nonstopmode", "tmp.tex"],
    ["dvisvgm", "--no-fonts", "-Z", "2", "tmp.dvi", "-o", "tmp.svg"]
  ]
}

Attention: You need to change gswin32c to the right name in your system.

  1. My card template
\documentclass{ctexart} %中文
\usepackage[papersize={2cm,1cm},centering]{geometry} %2cm * 1cm 
\usepackage{amssymb,amsmath}
\pagestyle{empty}
\begin{document}

\begin{center}

        %content


\end{center}

\end{document}
  1. Done.

Attention:

  1. When debugging, you need clean the temp.
  2. You need restart Anki to apply the settings.

Another Method: Use imagemagik

imagemagik can also convert pdf to png.

Support for svg

Well, if you want to use svg, you can use GhostPDL. However, GhostPDL must be compiled before using. So if you are interested, go ahead.


Too complex, I don't understand (For Anki users)

Well, for Anki users, it is quite complex if you are new to TeX, command line and so on, so if you don't want to trouble yourself, just use the default setting because Anki works well using HTML. (If you want to learn about TeX, command line and so on, then go ahead. This short answer may not satisfy you.)


Effect:

the effect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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