Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipse-dev] how to write plugin to render latex in (Java) code comments?



On Fri, May 20, 2022 at 8:21 AM Stephen Crowley <stephencrowley214@xxxxxxxxx> wrote:

Hi Mickael, thanks for the answer however that isn't quite what I had in mind. I want the mathematically typeset formulas to appear inline along with the java code

That's a very fun but not trivial topic!
As Alex mentioned, you can try using code-minings for that. Code Minings are attached to a some ranges of code in your editor, and can be used to draw extra things; they are more or less a combination for SWT's StyleRange & GlyphMetrics class which already allows to replace some text ranges by blank area, and of extra painting instructions to add your content in here. I think you can implement something similar for latex expressions, detect them,replace the text by a StyleRange/GlyphMetrics and draw a rendered image in place.
Snippet205 is probably the best source of inspiration.
 

This would most likely mean that the lines which do have  formulas to render with latex would probably have to be a bit taller to make them visible which might break the existing display code which I presume requires a fixed vertical spacing of lines?

The underlying StyledText widget doesn't mandate fixed vertical spacing of lines. it has a lot of flexibility: allow some vertical indent per line, and even characters/areas of different sizes on one line... See for example SWT's Snippet205 and Snippet211, and some others. Basically the low-level API is really capable of anything, the harder work is to interfere safely with lower level widget when coming from an editor.
 

An alternative would be to develop a convention, so that latex formulas would be represented as being within a Javadoc and within a special tag

called <math>

whichCouldSpanSeveralLines(x)=

like{\sup}.this()\int\someLatexStuff

</math>

Sorry, I don't know whether the Javadoc processor is extensible or customizable. That's something you should ask to the jdt-dev@xxxxxxxxxxx mailing-list.

Back to the top