TentativeConvert / LaTeX-Note-Importer-for-Anki

Add-on for the memory training program Anki, allowing to import and export notes written in LaTeX.
GNU Affero General Public License v3.0
32 stars 8 forks source link

Handling of multi-file documents. #8

Closed DurhamSmith closed 2 years ago

DurhamSmith commented 3 years ago

First off thanks for the great tool.

I often write multiple .tex files and \include{}or \input{} them. These files do not contain \begin{document} and \end{document}. This leads to a problem in importing them into anki, and the following error is reported:

Import failed. Debugging info: Traceback (most recent call last): File "/usr/share/anki/aqt/importing.py", line 308, in importFile importer.open() File "/home/dd/.local/share/Anki2/addons21/1199027445/lateximport.py", line 58, in open self.cacheFile() File "/home/dd/.local/share/Anki2/addons21/1199027445/lateximport.py", line 64, in cacheFile self.openFile() File "/home/dd/.local/share/Anki2/addons21/1199027445/lateximport.py", line 70, in openFile self.processFile(str(self.fileobj.read(), "utf-8")) File "/home/dd/.local/share/Anki2/addons21/1199027445/lateximport.py", line 212, in processFile self.preamble, document, ci = pieces[0] IndexError: list index out of range

With included \begin{document} and \end{document} the file is imported correctly. Would it be possible to remove the requirement for these tags for correct import?

TentativeConvert commented 3 years ago

As a quick fix, would you consider using the standalone package in your setup? If haven't tested this, but my understanding is that if you include \usepackage{standalone} in your main file, then you can use

\documentclass{standalone}
\begin{document}
... 
\end{document} 

in the files that you want to include.

It probably wouldn't be too difficult to fix the behaviour of the addon, but now that people have been using it for years I'm a bit afraid of breaking other peoples' workflows by changing it.

TentativeConvert commented 3 years ago

I wrote a fix for this problem for Anki 2.1. Could you test this and see whether it works for you before I deploy it via Ankis website? You just need to copy the current version of lateximport.py to your installation of the add-on. To find that installation, open Anki, go to Tools > Add-ons, select LatTeX Note Importer and click on View Files.

DurhamSmith commented 3 years ago

Marcus,

Thanks for the suggestion and fix. Both worked for me. I (quickly) tried some expected failure mode for the fix and it held up well. I will notify if I run into any issues with it. Appreciate the fast work and wonderful plugin.

D