Common LaTeX header for multiple note types

As the title suggests, I have several note types in which I use latex, and I would like them to share a common header (for custom commands/package imports that I often use), so I don’t have to copy the said header in every note type LaTeX header in the options. How can I achieve that?

Anki does not have a built-in feature to do this, but you could accomplish it by writing an add-on.

The add-on LaTeX’s Header/footer: edit everywhere allows to alter header and footer for latex in every note type simultaneously, see the bottom of this image. I last tested it in the spring.


Apparently it requires more tests :stuck_out_tongue:

An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-on support site.
Debug info:
Anki 2.1.35 (84dcaa86) Python 3.8.1 Qt 5.15.1 PyQt 5.15.1
Platform: Linux
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-11-02 16:48:53
Add-ons possibly involved: ⁨LaTeXs Headerfooter edit everywhere⁩

Caught exception:
Traceback (most recent call last):
  File "/home/adri/.local/share/Anki2/addons21/1863928230/", line 29, in onAdvanced
    frm.latexsvg.setChecked(self.model.get("latexsvg", False))
AttributeError: 'NoneType' object has no attribute 'get'

When I made the current version in the spring it worked. Since then I haven’t changed my latex settings.

This add-on overwrites a built-in function which can always break with future updates. But this was the only way to create the add-on.

Anki’s internals have changed a lot during this year and this add-on broke with Anki 2.1.28. In the meantime Arthur added a hook into the relevant function so that now an add-on can be made that shouldn’t break so easily.

I haven’t done much add-on development in the last months so I have forgotten a lot about pyqt and Anki’s internals (which have changed a lot over the year). But this modified file should work.

As always: use it at your own risk. Have a backup and know how to restore it. I didn’t test if the changes are properly synced. Let me know if it works for you.

1 Like

Very nice, the patch was effective, it worked as expected, even when synchronizing. Thanks! :grinning: