Rendering Chemfig Structures in Cloze Deletions

Hello everyone,

I’ve been having trouble rendering chemical structures using the chemfig package in cloze deletions in Anki. I’m trying to convert the LaTeX code into a PNG image to be displayed on my cards, but I’m encountering issues.

Here’s an example of the LaTeX code I’m trying to render:

\chemfig{
  H_3C-[:73]{\color{blue}N}
    *5(-
      *6(-(={\color{red}O})-{\color{blue}N}(-CH_3)-(={\color{red}O})-{\color{blue}N}(-CH_3)-=)
    --{\color{blue}N}=-)
}

I’ve attempted to modify the “Edit LaTeX build process” add-on in Anki to use pdflatex to generate a PDF and then use GraphicsMagick to convert the PDF to a PNG. Here’s my current configuration:

{
    "pngCommands": [
        [
            "pdflatex",
            "-interaction=nonstopmode",
            "tmp.tex"
        ],
        [
            "gm",
            "convert",
            "tmp.pdf",
            "tmp.png"
        ]
    ]
}

However, the output isn’t as expected. Instead of a correctly rendered chemical structure, I see a few characters mushed together. I’ve also tried removing the SVG commands section entirely, but this hasn’t resolved the issue.

I’ve confirmed that LaTeX is enabled in my Anki settings, and I’ve checked my card templates to ensure that the field containing my LaTeX code is included. I’ve also tested my LaTeX code in a separate LaTeX editor and it compiles without issue.

I’m at a loss for what to try next. Has anyone else encountered this issue, or does anyone have any suggestions for how to effectively render chemical structures using the chemfig package in Anki, especially in cloze deletions?

Thank you in advance for your help!

I can’t help you with the LaTeX issues, but you may wish to consider MathJax instead, which also supports chemfig I believe.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.