Search code examples
latextexanki

How to insert an image into Anki notes in latex format?


I am trying to create an Anki deck with, for example, a word on the front. Then I add the word with definitions on the back with a picture as well. But I am having trouble including graphics when there are already two fields (front text and back text). Here is an example note:

\begin{note}
\begin{field}
\textbf{\large ruminate}
\end{field}
\begin{field}
\textbf{\large ruminate}
\begin{description}
\item[verb] \hfill \\ 
chew the cuds

\item[verb] \hfill \\ 
reflect deeply on a subject

\end{description}
\end{field}
\end{note}

This note works just dandy, but when I try to include a graphic (as follows) Anki will not let me have two fields on the back.

\begin{note}
\begin{field}
\textbf{\large ruminate}
\end{field}
\begin{field}
\textbf{\large ruminate}
\begin{description}
\item[verb] \hfill \\ 
chew the cuds

\item[verb] \hfill \\ 
reflect deeply on a subject

\end{description}
\end{field}

\xplain(<img src="files/image.jpg" />)

\end{note}

I tried to use \includegraphics (Anki prohibits this, but I changed the source and got the package to work) but then on compiling the image could not be found.


Solution

  • Ok, so what did the trick was learning first to change the Anki card template.

    Front Template

    {{Word}}
    

    Back Template

    <img src="{{Picture}}" width="250" /><br>
    {{Definition}}
    
    <hr id=answer>
    

    Then, I had to just put the filename inside \xplain{} (making sure to include the graphic in my user's media folder). Then the note would look like this.

    \begin{note}
    \begin{field}
    \textbf{\large ruminate}
    \end{field}
    \begin{field}
    \textbf{\large ruminate}
    \begin{description}
    \item[verb] \hfill \\ 
    chew the cuds
    
    \item[verb] \hfill \\ 
    reflect deeply on a subject
    
    \end{description}
    \end{field}
    
    \xplain(<img src="image.jpg" />)
    
    \end{note}