yuzutech / kroki

Creates diagrams from textual descriptions!
https://kroki.io
MIT License
2.77k stars 206 forks source link

Math in PlantUML #442

Open danyill opened 3 years ago

danyill commented 3 years ago

I've been attempting to use AsciiMath in PlantUML using Kroki:

start
:hello world;
:This is defined on 
several **lines**
<math>x = (-b+-sqrt(b^2-4ac))/(2a)</math>;

end

On kroki.io I get:

image

On plantuml.com I get :

image

Could we enable asciimath/latexmath in PlantUML?

When I download plantuml.jar and run this, I get much the same output as on kroki.io

java -jar plantuml.jar test.puml

Interestingly, though I receive some warnings:

Warning: Nashorn engine is planned to be removed from a future JDK release
formula=x = (-b+-sqrt(b^2-4ac))/(2a)
Latex={x}=\frac{{-{b}\pm\sqrt{{{b}^{{2}}-{4}{a}{c}}}}}{{{2}{a}}}
java.lang.ClassNotFoundException: org.scilab.forge.jlatexmath.TeXFormula
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at net.sourceforge.plantuml.math.TeXIconBuilder.<init>(TeXIconBuilder.java:53)
        at net.sourceforge.plantuml.math.LatexBuilder.buildIcon(LatexBuilder.java:67)
        at net.sourceforge.plantuml.math.LatexBuilder.getImage(LatexBuilder.java:83)
        at net.sourceforge.plantuml.math.AsciiMath.getImage(AsciiMath.java:106)
        at net.sourceforge.plantuml.math.ScientificEquationSafe.getImage(ScientificEquationSafe.java:114)
        at net.sourceforge.plantuml.creole.atom.AtomMath.calculateDimensionSlow(AtomMath.java:68)
        at net.sourceforge.plantuml.creole.atom.AtomMath.calculateDimension(AtomMath.java:76)
        at net.sourceforge.plantuml.creole.Sea.add(Sea.java:60)
        at net.sourceforge.plantuml.creole.SheetBlock1.initMap(SheetBlock1.java:117)
        at net.sourceforge.plantuml.creole.SheetBlock1.calculateDimension(SheetBlock1.java:159)
        at net.sourceforge.plantuml.creole.SheetBlock2.calculateDimension(SheetBlock2.java:90)
        at net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileBox.calculateDimensionFtile(FtileBox.java:271)
        at net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile.calculateDimension(AbstractFtile.java:113)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple.calculateDimension(FtileAssemblySimple.java:129)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple.getTranslated1(FtileAssemblySimple.java:135)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple.getTranslateForSlow(FtileAssemblySimple.java:94)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple.getTranslateFor(FtileAssemblySimple.java:86)
        at net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorAssembly.assembly(FtileFactoryDelegatorAssembly.java:73)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator.assembly(FtileFactoryDelegator.java:179)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator.assembly(FtileFactoryDelegator.java:179)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator.assembly(FtileFactoryDelegator.java:179)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator.assembly(FtileFactoryDelegator.java:179)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator.assembly(FtileFactoryDelegator.java:179)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator.assembly(FtileFactoryDelegator.java:179)
        at net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator.assembly(FtileFactoryDelegator.java:179)
        at net.sourceforge.plantuml.activitydiagram3.InstructionList.createFtile(InstructionList.java:111)
        at net.sourceforge.plantuml.activitydiagram3.ftile.Swimlanes.drawU(Swimlanes.java:215)
        at net.sourceforge.plantuml.ugraphic.comp.CompressionXorYBuilder.getPiecewiseAffineTransform(CompressionXorYBuilder.java:51)
        at net.sourceforge.plantuml.ugraphic.comp.CompressionXorYBuilder.build(CompressionXorYBuilder.java:44)
        at net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3.exportDiagramInternal(ActivityDiagram3.java:212)
        at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:173)
        at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:140)
        at net.sourceforge.plantuml.PSystemUtils.exportDiagramsActivityDiagram3(PSystemUtils.java:176)
        at net.sourceforge.plantuml.PSystemUtils.exportDiagrams(PSystemUtils.java:95)
        at net.sourceforge.plantuml.SourceFileReaderAbstract.getGeneratedImages(SourceFileReaderAbstract.java:160)
        at net.sourceforge.plantuml.Run.manageFileInternal(Run.java:538)
        at net.sourceforge.plantuml.Run.processArgs(Run.java:422)
        at net.sourceforge.plantuml.Run.manageAllFiles(Run.java:389)
        at net.sourceforge.plantuml.Run.main(Run.java:198)

I think that means the dependency: https://mvnrepository.com/artifact/org.scilab.forge/jlatexmath is required.

Modern Java is a mystery to me (my last Java was in about ~2001) but after trying:

java -cp jlatexmath-1.0.7.jar:plantuml.jar net.sourceforge.plantuml.Run test.puml

I managed to correctly produce the diagram so I'm fairly sure this is the missing dependency.

I have not looked into why it does not work, I might have guessed we would be picking up dependencies from here where it is listed.

ggrossetie commented 3 years ago

Hey!

Nice findings! Indeed, JLatexMath is not included by default: https://plantuml.com/ascii-math I'm a bit concerned about: https://github.com/asciidoctor/asciidoctor-diagram/issues/259 and asked Pepijn for clarification.

Regarding the warning message, I initialy thought that PlantUML was tied to Nashorn but it's not the case, see: https://github.com/plantuml/plantuml/issues/394 In short, we can use GraalVM JavaScript Engine instead of Nashorn to get rid of this warning message and be compatible with Java 15+.

I will wait to hear from Pepijn before moving forward with JLatexMath.

ukubauka commented 3 years ago

In absence of an upcoming feature: This is a proposal which I could also make use of.

AshkanV commented 2 years ago

As @danyill described the directions, I used this command to start the Kroki server and the formulas rendered correctly:

java -cp jlatexmath-minimal-1.0.3.jar:kroki.jar io.vertx.core.Launcher

The jlatexmath-minimal-1.0.3.jar is a part of the package described at the end of this official PlantUML. Also it worked with the latest full jlatexmath (1.0.7) which I downloaded with its dependencies form jar-download

datafeng commented 1 year ago

hope new version add AsciiMath