2

For several days, I try to find an answer to my question, but without success.

In another question, it helped me to use "\ tikz" in Anki. Thank @gernot elsewhere.

I would like to include an image in an Anki card, using LaTeX language.

I know there are methods to include images in an Anki card that I found with Google, but it does not use LaTeX to insert.

In my previous question, I was given some advice, but for whatever reason it does not work. Thank you for your help.

I put the file in the td.png

/usr/local/texlive/2016/texmf-dist/tex/latex/mwe/

Error executing pdflatex.
Generated file: /var/folders/v1/psh6j3c139x1wkj2k38_77v40000gn/T/anki_temp/tmp.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./tmp.tex
LaTeX2e <2016/03/31>
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/standalone/standalone.cls
Document Class: standalone 2015/07/15 v1.2 Class to compile TeX sub-files stand
alone
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/local/texlive/2016/texmf-dist/tex/latex/standalone/standalone.cfg)
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/texlive/2016/texmf-dist/tex/latex/varwidth/varwidth.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/inputenc.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/utf8.def
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/t1enc.dfu)
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/ot1enc.dfu)
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/omsenc.dfu)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/local/texlive/2016/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te
x
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-li
sts.tex))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def
(/usr/local/texlive/2016/texmf-dist/tex/latex/ms/everyshi.sty))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex))
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.c
ode.tex))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-pdftex.d
ef
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-p
df.def)))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.
code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.
code.tex))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex
)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.
tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic
.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigo
nometric.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.rando
m.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.compa
rison.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.
code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round
.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.
code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integ
erarithmetics.code.tex)))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex)
)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.co
de.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconst
ruct.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage
.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.co
de.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicst
ate.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransform
ations.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.cod
e.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.c
ode.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathproce
ssing.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.co
de.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.cod
e.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.cod
e.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal.
code.tex))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.co
de.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretranspare
ncy.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns.
code.tex)))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.cod
e.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.
tex)
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-0-65.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version
-1-18.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/utilities/pgffor.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/utilities/pgfkeys.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex)
) (/usr/local/texlive/2016/texmf-dist/tex/latex/pgf/math/pgfmath.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/utilities/pgffor.code.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex)))
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.cod
e.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/libraries/pgflibraryplothan
dlers.code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/modules/pgfmodulematrix.cod
e.tex)
(/usr/local/texlive/2016/texmf-dist/tex/generic/pgf/frontendlayer/tikz/librarie
s/tikzlibrarytopaths.code.tex)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/mhchem/mhchem.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)
 (/usr/local/texlive/2016/texmf-dist/tex/latex/l3experimental/l3str/l3regex.sty

(/usr/local/texlive/2016/texmf-dist/tex/latex/l3experimental/l3str/l3tl-build.s
ty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3experimental/l3str/l3tl-analysi
s.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3experimental/l3str/l3flag.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3experimental/l3str/l3str-conver
t.sty)) (/usr/local/texlive/2016/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/chemgreek/chemgreek.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/easylist/easylist.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/SIstyle/sistyle.sty) (./tmp.aux)
(/usr/local/texlive/2016/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) ABD: EveryShipout initializing macros
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2016/texmf-dist/tex/latex/amsfonts/umsb.fd)

! LaTeX Error: File `td' not found.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.18 \includegraphics{td}

[1{/usr/local/texlive/2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./tmp.aux) )
(see the transcript file for additional information)</usr/local/texlive/2016/te
xmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb>
Output written on tmp.pdf (1 page, 8634 bytes).
Transcript written on tmp.log.

Edit_LaTeX_build_process:

newLaTeX = \
[
    ["pdflatex", "-interaction=nonstopmode", "tmp.tex"],
    ["sips", "-s", "format", "png", "tmp.pdf", "--out", "tmp.png"]
]
import anki.latex
anki.latex.latexCmds = newLaTeX

Options LaTeX Anki card.

Header:

\documentclass[12pt,border=1mm,varwidth]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amssymb, amsmath, amsfonts}
\usepackage{xcolor}
\usepackage{pgf, tikz}
\usepackage[version=4]{mhchem}
\usepackage[ampersand]{easylist}
\usepackage{fontenc}
\usepackage{graphicx}
\usepackage{sistyle}

\newcommand\tab[1][1cm]{\hspace*{#1}}

\begin{document}
\begin{varwidth}{100em}

Footer :

\end{varwidth}
\end{document}

Card setting.

Front Template :

[latex]{{cloze:Texte}}[/latex]

<div style='font-family: Arial; font-size: 20px;'>{{Enoncer}}</div>

Back Template :

[latex]{{cloze:Texte}}[/latex]
{{Extra}}

Styling :

.card {
 font-family: arial;
 font-size: 20px;
 text-align: center;
 color: black;
 background-color: white;
}

.cloze {
 font-weight: bold;
 color: blue;
}

@tym007 Yes, it is possible. Add \usepackage{graphicx} to the preamble, if it is not yet loaded by some other package (like pgfplots). Then [latex]\includegraphics{myfile.png}[/latex] should load the image. Some things may go wrong, though. Inspect tmp.tex and tmp.log, if it fails. E.g., if the image is too wide, use \includegraphics[width=3cm]{...}. If the filename or path contains special characters, you may need \string or \detokenize, see How to use tilde or space in includepdf filename?. – gernot Oct 10 at 20:34

@tym007 As a first test, use \includegraphics{example-image-a}. if you have a current TeXLive, then this image is on the search path. If this works, you know that any failures with your own images are due to either "image not found", "image too wide", or "strange characters in file name". – gernot Oct 10 at 20:38

@tym007 If the image is too big, then the preamble with the article class will generate a pdf with two pages, and the conversion to png fails (to be solved with [width=...]). The preamble with standalone will just cut the image, but not fail. – gernot Oct 10 at 20:44

In fact. For "\ usepackage {graphicx}" walking. We must put the image in the same file as the .tex. But on Anki, I do not know where to put it can be used with this function. An idea? – tym007 Oct 11 at 15:27

@tym007 Either give the full path, like \includegraphics{/usr/local/texlive/2016/texmf-dist/tex/late‌​x/mwe/example-image-‌​a.jpg}, or set the \graphicspath, or set the TEXINPUTS variable to include the directory with the images. If the file name or path includes spaces or special characters, see e.g. the answers to How to include graphics with spaces in their path?. For infos on \graphicspath, see the WikiBook on LaTeX/Importing Graphics. – gernot Oct 11 at 16:06

I try with this code, but it does not. '\includegraphics{/usr/local/texlive/2016/texmf-dist/tex/lat‌​‌​e‌​x/mwe/td.jpg}' – tym007 2 days ago

@tym007 How does tmp.tex look like? What does tmp.log say? What happens when you compile tmp.tex yourself? Does the image /usr/local/texlive/2016/texmf-dist/tex/lat‌​‌​ex/mwe/td.jpg really exist on your system? It doesn't on my system ... If td.jpg is your image, you have to use the path of this file instead of /usr/local/texlive/2016/texmf-dist... – gernot 2 days ago

  • So \includegraphics{example-image-a.jpg} works, but \includegraphics{td.jpg} does not, even though they are in the same directory /usr/local/texlive/2016/texmf-dist/tex/lat‌​‌​e‌​x/mwe. The reason is that the files in the texmf-tree are indexed; after adding files one has to re-index the tree using mktexlsr from the command line. I guess that putting your image in the distribution tree was just a test (and maybe an act of despair), and that you know that one shouldn't put local files into this tree as they will vanish with the next upgrade. – gernot Oct 15 '16 at 14:20
  • Have you finally succeeded in adding images to your cards? If you still encounter problems I suggest that we meet in a chatroom and solve it together at the spot; exchanging comments with big delays is cumbersome. – gernot Oct 16 '16 at 7:10
  • Hello, the solution you offered me work, but I do not know how to change the syntax {{ }} of Anki card Cloze. – tym007 Oct 16 '16 at 14:33
  • You don't have to change {{...}} if it is Anki code; why do you want to? There may only be a problem if the code meant for LaTeX contains '{{'. In this case the preprocessing by Anki may interpret it, even though it shouldn't. In this case you can replace it by something that means the same in LaTeX but doesn't confuse Anki. The same for '}}', which might be interpreted as the end of a cloze text. See also the advice in the Anki Manual regarding }}. – gernot Oct 16 '16 at 14:59
  • Don't worry until you run into a conrete problem. (Do you have one right at the moment?) If you then see that double braces are involved, reread what's written here and in the Anki manual, and ask again with this new problem. – gernot Oct 16 '16 at 15:03
2

Anki uses some temporary directory for compilation, so you have to give the path to your images explicitly. Suppose the directory is /home/gernot/anki and contains an image duck.jpg. Set the preamble in Anki via Tools | Manage Note Types | your cloze note type | Options to

\documentclass[12pt,border=1mm,varwidth]{standalone}
\usepackage{graphicx}
\graphicspath{{/home/gernot/anki/}}
\begin{document}

Add a card of your cloze note type with the following contents in the Text field:

[latex]\begin{center}\includegraphics{duck}\\\relax {{c1::duck}}\end{center}[/latex] 

Then Anki will generate the two cards

enter image description here enter image description here

Some things to observe:

  • The path in \graphicspath has to end with a slash /.

  • Bare in mind that strings like {{c1::XXX}} will be replaced by [...] on one card and by XXX on the other one. You have to make sure that your code is correct in both cases. In the example above, writing \\{{c1::duck}} gives an error since \\[...] is interpreted as \\ with an optional argument. Writing \\\relax{{c1::duck}} still gives an error, since the string becomes \\\relaxduck on the second card and \relaxduck is an undefined command. Therefore one has to put a space, a line end or {} inbetween.

  • If the LaTeX code happens to contain double braces {{, it may be mistaken as Anki notation. Replace it by {%+new line+{ or, if acceptable from the LaTeX point of view, by { {.

  • If the path or the file name of the image contains special characters (spaces, tildes, dots) one may have to take extra precautions. See How to use \graphicspath? \includegraphics: Dots in filename; but remember the last point about avoiding double braces.

(duck image from Wikipedia)

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.