Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用jlatextmath在导出的svg图像中保留变量名?_Java_Svg_Latex_Tex - Fatal编程技术网

Java 如何使用jlatextmath在导出的svg图像中保留变量名?

Java 如何使用jlatextmath在导出的svg图像中保留变量名?,java,svg,latex,tex,Java,Svg,Latex,Tex,我正在使用jlatexmath数学将公式转换为SVG图像。我需要在导出的svg图像中保留变量名称。我已经使用了Fontashapes参数。输出不好:不是数学公式。 如何在输出svg图像中保留变量名?现在,所有变量都绘制在svg图像上(仅坐标) 是否可以绘制公式并保留可变词 我稍后会将这些词用于超链接目的 代码如下: import java.awt.Color; import java.awt.Dimension; import java.awt.Insets; import java.io.Fi

我正在使用jlatexmath数学将公式转换为SVG图像。我需要在导出的svg图像中保留变量名称。我已经使用了Fontashapes参数。输出不好:不是数学公式。 如何在输出svg图像中保留变量名?现在,所有变量都绘制在svg图像上(仅坐标)

是否可以绘制公式并保留可变词

我稍后会将这些词用于超链接目的

代码如下:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

import javax.swing.JLabel;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.svggen.SVGGraphics2D;
import org.scilab.forge.jlatexmath.DefaultTeXFont;
import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
import org.scilab.forge.jlatexmath.TeXIcon;
import org.scilab.forge.jlatexmath.cyrillic.CyrillicRegistration;
import org.scilab.forge.jlatexmath.greek.GreekRegistration;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;

public class Main {

    public static void main(final String args[]) throws IOException {
        toSVG("End_fD = (Tos_f/2)*(1/60)*(Tos_f)", "Example.svg", true);
        System.out.println("done");
    }

    public static void toSVG(final String latex, final String file, final boolean fontAsShapes) throws IOException {
        DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
        String svgNS = "http://www.w3.org/2000/svg";
        Document document = domImpl.createDocument(svgNS, "svg", null);
        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);

        SVGGraphics2D g2 = new SVGGraphics2D(ctx, fontAsShapes);

        DefaultTeXFont.registerAlphabet(new CyrillicRegistration());
        DefaultTeXFont.registerAlphabet(new GreekRegistration());

        TeXFormula formula = new TeXFormula(latex);
        TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
        icon.setInsets(new Insets(5, 5, 5, 5));
        g2.setSVGCanvasSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
        g2.setColor(Color.white);
        g2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());

        JLabel jl = new JLabel();
        jl.setForeground(new Color(0, 0, 0));
        icon.paintIcon(jl, g2, 0, 0);

        boolean useCSS = true;
        FileOutputStream svgs = new FileOutputStream("target/" + file);
        Writer out = new OutputStreamWriter(svgs, "UTF-8");
        g2.stream(out);
        svgs.flush();
        svgs.close();
    }
}