2

I installed MikTeX, updated everything, downloaded the passivetex package, ran everything as admin, checked the depositories and everything, and yet I cannot get LaTeX to work with Anki. Here is the error message I get:

Error executing latex.
Generated file: C:\Users\Leon\AppData\Local\Temp\anki_temp\tmp.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6930 64-bit)
entering extended mode
(tmp.tex
LaTeX2e 
("C:\Users\Leon\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\article.cls"
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
("C:\Users\Leon\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\size12.clo"))
("C:\Users\Leon\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\fontenc.sty"
("C:\Users\Leon\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\t1enc.def"))
("C:\Users\Leon\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\inputenc.sty"

! LaTeX Error: File `utf8x.def' not found.

Type X to quit or  to proceed,
or enter new name. (Default extension: def)

Enter file name: 
! Emergency stop.
 

l.165 \endinput


No pages of output.
Transcript written on tmp.log.

Any help with this? I am on Windows 10. EDIT: I have the admin premissions and have turned off autoupdates in MikTeX.

  • Usual comment we need mwe with preamble that causes anki to be loaded so we can compare sequence on both MiKTeX and alternate systems From guide "On Windows, go to Settings in MikTek’s maintenance window, and make sure "Install missing packages on the fly" is set to "No", not to "Ask me first". If you continue to have difficulties, one user reported that running Anki as an administrator until all the packages were fetched helped." see apps.ankiweb.net/docs/… – KJO Jan 21 at 15:43
  • And the underscore "_" in the path doesn't cause the error? – Keks Dose Jan 21 at 16:18
  • @KeksDose No that is standard anki it loads a tmp.tex file to that location what one user found helpful having problems with dvipng was to run CMD (as admin ?) then~~> CD %AppData%/Local/Temp/anki_temp/ (then in that directory checking the cmd prompt reflects your location run>) dvipng tmp.tex ~SO IN THIS CASE~ try pdfLaTeX tmp.tex and> latex tmp.tex – KJO Jan 21 at 16:52
  • @KJO I have read all of that and followed the instructions but no improvement.. – Leon Hudak Jan 21 at 17:09
  • 1
    utf8x.def is in the ucs package, so you need to install this, or better don't use it in your document. utf8x is seldom needed. – Ulrike Fischer Jan 21 at 17:30
2

For a fresh user to Anki using LaTeX and Miktex there is a sharp initial learning curve with several pitfalls. When you enter LaTeX code into Anki it is best to start with the simplest of examples so to get a Question and Answer such as

enter image description here

You need to start with this simple entry enter image description here

Does the divergent p-series 
[latex]\begin{math}\sum_{k = 1}^{\infty}\frac{1}{k}\end{math}[/latex]
 converge?

The series converges for p>1 and diverges for 0<p≤1. With p=1 it is called the Harmonic Series.

The first error message may be

Error executing latex.
Generated file: C:\Users\yourname\AppData\Local\Temp\anki_temp\tmp.tex
Have you installed latex and dvipng/dvisvgm?  

This shows you have not installed MiKTeX correctly (including setting the paths)

IF you get other error messages then either your latex code is not right or MiKTeX has not been configured correctly.

One test to see what is happening is to check Anki's TeX output which is a file
%temp%\anki_temp\tmp.tex (you can enter %temp%\anki_temp in windows explorer address bar to get there quickly) If you open tmp.tex in notepad then check/verify its contents are identical to the MWE shown below .

It is best to run MiKTeX-console and ensure it is fully stable before Anki calls it in the background.

The best way to check MiKTeX can run the same code as above is to use the included TeXworks editor and run the same minimal example until it works.

\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath}
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}

\begin{math}\sum_{k = 1}^{\infty}\frac{1}{k}\end{math}
\end{document}

so it should show enter image description here

Once you are confident that the above simple sample works with TeXworks IT should then work in Anki and in the temp directory (see above) 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.


In summary
Although the Anki manual and other older guides suggest settings are changed to "Install missing packages on the fly" is set to "No", not to "Ask me first" It is essential that MiKTeX is allowed to update itself

Thus I recommend the following (until someone corrects me as to why not?)
DO use the setting "Always install missing packages on the fly" until you have a stable setup, then (if you must) switch it to no.

While you are there in the console ensure amsfonts and miktex-dvipng-bin-2.9 have been added to the active packages (there should be a date under "installed on", it has also been recommended to include passivetex and ucs packages to clear the above utf8x error, however the simple example above runs correctly without it. It is easy to add or remove it using + and -.

Most importantly, periodically enter MiKTeX-console to manually force Tasks Refresh file name database as well as Refresh font map files this ensures your errors messages are minimal.

Whatever the problem is with Anki this TeX forum will require to see the contents of tmp.tex (what we may call the MWE) within your question so as to see what caused any error messages reported in the logs. It may also be useful to add the [latex] blah bla blah [/latex] line you used within Anki (although that should by default be included in the tmp.tex that you post).

If you customise LaTeX calling from Anki using the "Edit LaTeX build process" with the add-on from https://ankiweb.net/shared/info/937148547 or one of its variants then we will also need to know it was added and certainly what was changed especially if you extend to tikz or or other packages.

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.