public void setLaTeX(Application app, String str) { if (str.indexOf('"') > -1) { GeoText text = app.getKernel().getAlgebraProcessor().evaluateToText(str, false, false); if (text != null) { text.setLaTeX(true, false); str = text.getTextString(); } else { // bad syntax, remove all quotes and use raw string while (str.indexOf('"') > -1) str = str.replace('"', ' '); // latexPreview.setLaTeX(str); } } else { // latexPreview.setLaTeX(str); } String f = str.trim(); if (f.length() >= 2 && f.startsWith("$") && f.endsWith("$")) { f = f.substring(1, f.length() - 1); } im = (BufferedImage) TeXFormula.getPartialTeXFormula(f) .createBufferedImage( TeXConstants.STYLE_DISPLAY, defaultSize, Color.black, Color.white); /* icon = TeXFormula.getPartialTeXFormula(f).createTeXIcon( TeXConstants.STYLE_DISPLAY, defaultSize); if (icon == null) { icon = TeXFormula.getPartialTeXFormula("").createTeXIcon( TeXConstants.STYLE_DISPLAY, defaultSize); } width = icon.getIconWidth(); height = icon.getIconHeight();*/ width = im.getWidth(); height = im.getHeight(); Dimension dim = new Dimension(width + 2 * INSET, height + 2 * INSET); setPreferredSize(dim); setSize(dim); setLocation(0, 0); setVisible(true); repaint(); }
// calc the current value of the arithmetic tree @Override public final void compute() { boolean useLaTeX = true; if (!geo.isDefined() || (substituteVars != null && !substituteVars.isDefined()) || showName != null && !showName.isDefined()) { text.setTextString(""); } else { boolean substitute = substituteVars == null ? true : substituteVars.getBoolean(); boolean show = showName == null ? false : showName.getBoolean(); text.setTemporaryPrintAccuracy(); // Application.debug(geo.getFormulaString(StringType.LATEX, substitute )); if (show) { text.setTextString(geo.getLaTeXAlgebraDescription(substitute)); if (text.getTextString() == null) { text.setTextString(geo.getAlgebraDescriptionTextOrHTML()); useLaTeX = false; } } else { if (geo.isGeoText()) { // needed for eg Text commands eg FormulaText[Text[ text.setTextString(((GeoText) geo).getTextString()); } else { text.setTextString(geo.getFormulaString(StringType.LATEX, substitute)); } } text.restorePrintAccuracy(); } text.setLaTeX(useLaTeX, false); /* int tempCASPrintForm = kernel.getCASPrintForm(); kernel.setCASPrintForm(StringType.LATEX); text.setTextString(geo.getCommandDescription()); kernel.setCASPrintForm(tempCASPrintForm);*/ }
/** * Get the text string of a GeoText * * @param geo the GeoText * @return the text value of the GeoText */ public static String getTextString(GeoText geo) { return geo.getTextString(); }