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
You need to start with this simple entry
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 could mean you have not installed MiKTeX correctly (including setting the paths). To check this open command line and try and run latex, dvipng, and dvisvgm and make sure the system can find these. If the system can find all these programs, the error message can also be generated by Anki not having sufficient privileges to fetch all necessary packages. Try running Anki one time in Administrator mode.
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
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.
Most likely cause is a dead console session in memory or the editor /viewer is stuck in some update loop.
Next most likely cause can be interference by antivirus or other systems monitors.
That good old advice still stands Have you tried pressing the off key at the wall (joke)
Seriously, a reboot should kill any duplicate sessions. Then on start-up DO NOT run anything other than MiKTeX-console, try at first to run without elevation to admin rights, since in this case you are using a basic install and try again.
IF message is still the same again, then you need to go to MiKTeX support site to check if there are others with similar issues (open or closed) and if not then open a fresh one.
https://github.com/MiKTeX/miktex/issues
Best Answer
The editor you are using (in this case VS Code) simply uses the first application named
pdflatex
(orlatexmk
,lualatex
depending on your recipe) it can find.Or more specific: There is a special global variable named
PATH
which stores all directories that contain applications. When installing MikTeX or TeXLive, they will append their directories to this variable. If you now run a command likepdflatex
in a terminal (cmd
orPowerShell
on Windows) it will go through all directories in thePATH
-variable and look for thepdflatex.exe
-executable. You should be able to determine which application is run by simply executingpdflatex -version
in a terminal. It will show with which distribution it came. VS Code does nothing else than using the systems environment. So you shouldn't have to configure it in any way.However, what you can do is ensuring that the 'TeXLive' executable can be found before the 'MikTeX' executable. This can be done by moving the respective path entries up in the list (for example as described here