Created attachment 63563 [details] patch to add LaTeX support to annotations Version: unspecified OS: Linux I tried to add support for LaTeX formulas in annotations to Okular (see attachment). I reused some parts of Kopete's LaTeX plugin to do so. Maybe it would be better to add this code to some library if more applications start to support LaTeX formulas... If you think that this functionality is useful I can try to finish my patch. Reproducible: Didn't try Expected Results: Render LaTeX formulas inside $$...$$
Created attachment 63564 [details] Screenshot
This feature goes a bit against the fact that we are trying to save our annotations to file in case of PDF that support annotations, the problem is that this is not supported as far as i know by PDF thus makes our already hard work even harder
I thought about that, too. However, there is no way to store formulas in PDF annotations as far as I know. So the best one can do is to store them as plain Latex-style code (as I did until now). But if I do so why should not Okular allow to render them properly while all other readers just display the plain code? If that is not wanted I am ok with it, though.
Oh, i see what you did is that any annotation out there with $$ is rendered with latex, do not think it is a good idea, i am sure there are files out there with $$ in the text and they did not want a to represent a latex formula
I think most annotations won't include $$valid_latex_code$$ if it is not on purpose but you are right that we cannot be sure about that. Maybe a solution would be not to alter the tooltip but add a second view in the opened annotation that can be toggled by a small button? There is no need to save the status of the view, just default to the one that does not render LaTeX when opening it...
What i would add is something that detects if there is valid latex code between $$ and then adds a status message on the top saying something like "This comment seems to have latex formula, click here to render it", and if it is clicked, the formula is rendered. What do you think?
(In reply to comment #2) > annotations to file in case of PDF that support annotations, the problem is > that this is not supported as far as i know by PDF thus makes our already hard > work even harder PDF supports Appearance Streams for annotations, so we could have latex render the formula into a PDF file and create the AP entry in the annotation dict from the pdf. We could also include some special entry in the annotation dict to indicate that this is in fact a rendered LaTeX formula and what the LaTeX code was so that we could edit it afterwards... I had some luck with this approach, however the saving was done by podofo not poppler. Same way we could --- I suppose at least --- add a custom field to the annotation xml entry to indicate that it is a formula so that we don't need to do automatic guessing (maybe even create a new annotation type). If that is a no-go, I also like Albert's approach in comment #6.
> PDF supports Appearance Streams for annotations, so we could have latex render > the formula into a PDF file and create the AP entry in the annotation dict from > the pdf. We could also include some special entry in the annotation dict to > indicate that this is in fact a rendered LaTeX formula and what the LaTeX code > was so that we could edit it afterwards... Is it a good idea to include a rendered formula? This way, we cannot adjust font size and color easily... > Same way we could --- I suppose at least --- add a custom field to the > annotation xml entry to indicate that it is a formula so that we don't need > to do automatic guessing (maybe even create a new annotation type). If this is possible and can be stored in the PDF, too, it is probably the best solution. But if we decide to go this way I think I need some help to implement it. Otherwise I can create a patch for the solution as proposed in comment #6.
Including the rendered formula has the benefit that other programs (i.e. Acrobat) can render the formula too, but that obviously depends on another missing feature that is saving annotations back to the file.
(In reply to comment #8) > Is it a good idea to include a rendered formula? This way, we cannot adjust > font size and color easily... As Albert said, it would have the benefit that other viewers would be able to display it, or okular could be use the rendered formula on systems where there is no latex installed. Since we would also store the latex code used to generate the formula, there would be no problem with adjusting the color, font size, etc. HOWEVER, as Albert said, currently poppler (the pdf library used by okular) doesn't support saving annotations back to the file. I think there was a GSoC project to implement it in poppler, but I have no idea how that went. So, until this is supported in poppler, I think Albert's approach mentioned in #6 would be the best way forward. Although personaly I would probably default to rendering the formula and showing the code on click instead of showing the code and rendering on click. This is, however, for Albert to decide, I think. I would be willing to help you with this, however currently I do not have much spare time to work on it :-(
**** As Albert said, currently poppler (the pdf library used by okular) doesn't support saving annotations back to the file. **** I did not say that at all. I said Okular doesn't do it, poppler has support for it since a while ago (might be needed to be improved or might not).
Sorry, I misinterpreted your comment. But this is good news :-) I will have to look at poppler again. (In reply to comment #11) > **** > As Albert said, currently poppler (the pdf library used by okular) > doesn't support saving annotations back to the file. > **** > I did not say that at all. I said Okular doesn't do it, poppler has support for > it since a while ago (might be needed to be improved or might not).
While it would be nice to save the rendered formula to the pdf, I think it's something we can still implement once okular has support for saving annotations to it. I created a patch to support something like Albert's proposal in comment #6. What do you think?
Created attachment 63725 [details] LatexRenderer class
Created attachment 63726 [details] adds support for latex annotations to the annotation window
Created attachment 63727 [details] new screenshot
I'd like a bit more of user feedback in case latex is not installed, as far as i can see now what would happen is that he clicks the button and gets nothing?
You are right, this should be changed. There are two possibilities: Either do not display the button at all if latexis not installed or do so but show a message box saying "latex / pdftex is not installed". We can also display an error message if latex fails because of invalid syntax. What do you prefer?
Created attachment 63850 [details] LatexRenderer class
Created attachment 63851 [details] adds support for latex annotations to the annotation window
I think it is best to always display the button so that the user gets feedback why his code does not work. I attached a patch for that.
Commited, thanks a lot for your work, if you are interested in doing more okular work do not hesitate to contact me at aacid@kde.org
Thanks. I have just noticed that you removed "m_filelist". This way, the temporary files will not get deleted on destruction of the annotation window. Is this a good idea?
Thanks for the review, i actually had a look at the code in the destructor and for some reason overlooked the QFile::remove there and then m_filelist did not make any sense anymore and i removed it altogether. But obviously, yes it is a bad idea to remove it, i've readded it now, can you have a second look to be sure i did not break something else?
Seems to be right now.
*** Bug 213251 has been marked as a duplicate of this bug. ***