Class TeXFormula

  • Direct Known Subclasses:
    ArrayOfAtoms

    public class TeXFormula
    extends java.lang.Object
    Represents a logical mathematical formula that will be displayed (by creating a TeXIcon from it and painting it) using algorithms that are based on the TeX algorithms.

    These formula's can be built using the built-in primitive TeX parser (methods with String arguments) or using other TeXFormula objects. Most methods have (an) equivalent(s) where one or more TeXFormula arguments are replaced with String arguments. These are just shorter notations, because all they do is parse the string(s) to TeXFormula's and call an equivalent method with (a) TeXFormula argument(s). Most methods also come in 2 variants. One kind will use this TeXFormula to build another mathematical construction and then change this object to represent the newly build construction. The other kind will only use other TeXFormula's (or parse strings), build a mathematical construction with them and insert this newly build construction at the end of this TeXFormula. Because all the provided methods return a pointer to this (modified) TeXFormula (except for the createTeXIcon method that returns a TeXIcon pointer), method chaining is also possible.

    Important: All the provided methods modify this TeXFormula object, but all the TeXFormula arguments of these methods will remain unchanged and independent of this TeXFormula object!

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  TeXFormula.TeXIconBuilder
      Apply the Builder pattern instead of using the createTeXIcon(...) factories
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        TeXFormula()
      Creates an empty TeXFormula.
        TeXFormula​(java.lang.String s)
      Creates a new TeXFormula by parsing the given string (using a primitive TeX parser).
        TeXFormula​(java.lang.String s, boolean firstpass)  
        TeXFormula​(java.lang.String s, java.lang.String textStyle)  
        TeXFormula​(java.lang.String s, java.lang.String textStyle, boolean firstpass, boolean space)  
        TeXFormula​(java.lang.String s, java.util.Map<java.lang.String,​java.lang.String> map)
      Creates a new TeXFormula by parsing the given string (using a primitive TeX parser).
        TeXFormula​(TeXFormula f)
      Creates a new TeXFormula that is a copy of the given TeXFormula.
      protected TeXFormula​(TeXParser tp)
      Creates an empty TeXFormula.
      protected TeXFormula​(TeXParser tp, java.lang.String s)
      Creates a new TeXFormula by parsing the given string (using a primitive TeX parser).
      protected TeXFormula​(TeXParser tp, java.lang.String s, boolean firstpass)  
      protected TeXFormula​(TeXParser tp, java.lang.String s, java.lang.String textStyle)  
      protected TeXFormula​(TeXParser tp, java.lang.String s, java.lang.String textStyle, boolean firstpass, boolean space)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TeXFormula add​(java.lang.String s)
      Parses the given string and inserts the resulting formula at the end of the current TeXFormula.
      TeXFormula add​(Atom el)
      Inserts an atom at the end of the current formula
      TeXFormula add​(TeXFormula f)
      Inserts the given TeXFormula at the end of the current TeXFormula.
      static void addPredefinedCommands​(java.io.InputStream xmlFile)  
      static void addPredefinedTeXFormula​(java.io.InputStream xmlFile)  
      TeXFormula addStrut​(int type)
      Inserts a strut box (whitespace) with the given width, height and depth (in the given unit) at the end of the current TeXFormula.
      TeXFormula addStrut​(int unit, float width, float height, float depth)
      Inserts a strut box (whitespace) with the given width, height and depth (in the given unit) at the end of the current TeXFormula.
      TeXFormula addStrut​(int widthUnit, float width, int heightUnit, float height, int depthUnit, float depth)
      Inserts a strut box (whitespace) with the given width (in widthUnits), height (in heightUnits) and depth (in depthUnits) at the end of the current TeXFormula.
      static void addSymbolMappings​(java.io.InputStream in, java.lang.String name)  
      static void addSymbolMappings​(java.lang.String file)  
      TeXFormula append​(boolean isPartial, java.lang.String s)  
      TeXFormula append​(java.lang.String s)  
      TeXFormula centerOnAxis()
      Centers the current TeXformula vertically on the axis (defined by the parameter "axisheight" in the resource "DefaultTeXFont.xml".
      java.awt.Image createBufferedImage​(int style, float size, java.awt.Color fg, java.awt.Color bg)  
      static java.awt.Image createBufferedImage​(java.lang.String formula, int style, float size, java.awt.Color fg, java.awt.Color bg)  
      void createGIF​(int style, float size, java.lang.String out, java.awt.Color bg, java.awt.Color fg)  
      void createImage​(java.lang.String format, int style, float size, java.lang.String out, java.awt.Color bg, java.awt.Color fg, boolean transparency)  
      void createJPEG​(int style, float size, java.lang.String out, java.awt.Color bg, java.awt.Color fg)  
      void createPNG​(int style, float size, java.lang.String out, java.awt.Color bg, java.awt.Color fg)  
      TeXIcon createTeXIcon​(int style, float size)
      Creates a TeXIcon from this TeXFormula using the default TeXFont in the given point size and starting from the given TeX style.
      TeXIcon createTeXIcon​(int style, float size, boolean trueValues)  
      TeXIcon createTeXIcon​(int style, float size, int type)  
      TeXIcon createTeXIcon​(int style, float size, int widthUnit, float textwidth, int align)  
      TeXIcon createTeXIcon​(int style, float size, int widthUnit, float textwidth, int align, int interlineUnit, float interline)  
      TeXIcon createTeXIcon​(int style, float size, int type, int widthUnit, float textwidth, int align)  
      TeXIcon createTeXIcon​(int style, float size, int type, int widthUnit, float textwidth, int align, int interlineUnit, float interline)  
      TeXIcon createTeXIcon​(int style, float size, int type, java.awt.Color fgcolor)  
      static TeXFormula get​(java.lang.String name)
      Get a predefined TeXFormula.
      static TeXFormula getAsText​(java.lang.String text, int alignment)  
      static org.scilab.forge.jlatexmath.TeXFormula.FontInfos getExternalFont​(java.lang.Character.UnicodeBlock block)  
      boolean getLookAtLastAtom()  
      static TeXFormula getPartialTeXFormula​(java.lang.String formula)  
      static boolean isRegisteredBlock​(java.lang.Character.UnicodeBlock block)  
      static void registerExternalFont​(java.lang.Character.UnicodeBlock block, java.lang.String fontName)  
      static void registerExternalFont​(java.lang.Character.UnicodeBlock block, java.lang.String sansserif, java.lang.String serif)  
      static void registerFonts​(boolean b)  
      TeXFormula setBackground​(java.awt.Color c)
      Changes the background color of the current TeXFormula into the given color.
      TeXFormula setColor​(java.awt.Color c)
      Changes the (foreground) color of the current TeXFormula into the given color.
      void setDEBUG​(boolean b)  
      static void setDefaultDPI()
      Set the default target DPI to the screen dpi (only if we're in non-headless mode)
      static void setDPITarget​(float dpi)
      Set the DPI of target
      TeXFormula setFixedTypes​(int leftType, int rightType)
      Sets a fixed left and right type of the current TeXFormula.
      void setLaTeX​(java.lang.String ltx)
      Change the text of the TeXFormula and regenerate the root
      void setLookAtLastAtom​(boolean b)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PIXELS_PER_POINT

        public static float PIXELS_PER_POINT
      • predefinedTeXFormulas

        public static java.util.Map<java.lang.String,​TeXFormula> predefinedTeXFormulas
      • predefinedTeXFormulasAsString

        public static java.util.Map<java.lang.String,​java.lang.String> predefinedTeXFormulasAsString
      • symbolMappings

        public static java.lang.String[] symbolMappings
      • symbolTextMappings

        public static java.lang.String[] symbolTextMappings
      • symbolFormulaMappings

        public static java.lang.String[] symbolFormulaMappings
      • externalFontMap

        public static java.util.Map<java.lang.Character.UnicodeBlock,​org.scilab.forge.jlatexmath.TeXFormula.FontInfos> externalFontMap
      • middle

        public java.util.List<MiddleAtom> middle
      • jlmXMLMap

        protected java.util.Map<java.lang.String,​java.lang.String> jlmXMLMap
      • root

        public Atom root
      • textStyle

        public java.lang.String textStyle
      • isColored

        public boolean isColored
    • Constructor Detail

      • TeXFormula

        public TeXFormula()
        Creates an empty TeXFormula.
      • TeXFormula

        public TeXFormula​(java.lang.String s,
                          java.util.Map<java.lang.String,​java.lang.String> map)
                   throws ParseException
        Creates a new TeXFormula by parsing the given string (using a primitive TeX parser).
        Parameters:
        s - the string to be parsed
        Throws:
        ParseException - if the string could not be parsed correctly
      • TeXFormula

        public TeXFormula​(java.lang.String s)
                   throws ParseException
        Creates a new TeXFormula by parsing the given string (using a primitive TeX parser).
        Parameters:
        s - the string to be parsed
        Throws:
        ParseException - if the string could not be parsed correctly
      • TeXFormula

        public TeXFormula​(java.lang.String s,
                          java.lang.String textStyle,
                          boolean firstpass,
                          boolean space)
                   throws ParseException
        Throws:
        ParseException
      • TeXFormula

        public TeXFormula​(TeXFormula f)
        Creates a new TeXFormula that is a copy of the given TeXFormula.

        Both TeXFormula's are independent of one another!

        Parameters:
        f - the formula to be copied
      • TeXFormula

        protected TeXFormula​(TeXParser tp)
        Creates an empty TeXFormula.
      • TeXFormula

        protected TeXFormula​(TeXParser tp,
                             java.lang.String s)
                      throws ParseException
        Creates a new TeXFormula by parsing the given string (using a primitive TeX parser).
        Parameters:
        s - the string to be parsed
        Throws:
        ParseException - if the string could not be parsed correctly
    • Method Detail

      • isRegisteredBlock

        public static boolean isRegisteredBlock​(java.lang.Character.UnicodeBlock block)
      • getExternalFont

        public static org.scilab.forge.jlatexmath.TeXFormula.FontInfos getExternalFont​(java.lang.Character.UnicodeBlock block)
      • registerExternalFont

        public static void registerExternalFont​(java.lang.Character.UnicodeBlock block,
                                                java.lang.String sansserif,
                                                java.lang.String serif)
      • registerExternalFont

        public static void registerExternalFont​(java.lang.Character.UnicodeBlock block,
                                                java.lang.String fontName)
      • setDPITarget

        public static void setDPITarget​(float dpi)
        Set the DPI of target
        Parameters:
        dpi - the target DPI
      • setDefaultDPI

        public static void setDefaultDPI()
        Set the default target DPI to the screen dpi (only if we're in non-headless mode)
      • getPartialTeXFormula

        public static TeXFormula getPartialTeXFormula​(java.lang.String formula)
        Parameters:
        a - formula
        Returns:
        a partial TeXFormula containing the valid part of formula
      • registerFonts

        public static void registerFonts​(boolean b)
        Parameters:
        b - true if the fonts should be registered (Java 1.6 only) to be used with FOP.
      • setLaTeX

        public void setLaTeX​(java.lang.String ltx)
                      throws ParseException
        Change the text of the TeXFormula and regenerate the root
        Parameters:
        ltx - the latex formula
        Throws:
        ParseException
      • add

        public TeXFormula add​(Atom el)
        Inserts an atom at the end of the current formula
      • add

        public TeXFormula add​(java.lang.String s)
                       throws ParseException
        Parses the given string and inserts the resulting formula at the end of the current TeXFormula.
        Parameters:
        s - the string to be parsed and inserted
        Returns:
        the modified TeXFormula
        Throws:
        ParseException - if the string could not be parsed correctly
      • add

        public TeXFormula add​(TeXFormula f)
        Inserts the given TeXFormula at the end of the current TeXFormula.
        Parameters:
        f - the TeXFormula to be inserted
        Returns:
        the modified TeXFormula
      • setLookAtLastAtom

        public void setLookAtLastAtom​(boolean b)
      • getLookAtLastAtom

        public boolean getLookAtLastAtom()
      • centerOnAxis

        public TeXFormula centerOnAxis()
        Centers the current TeXformula vertically on the axis (defined by the parameter "axisheight" in the resource "DefaultTeXFont.xml".
        Returns:
        the modified TeXFormula
      • addStrut

        public TeXFormula addStrut​(int unit,
                                   float width,
                                   float height,
                                   float depth)
                            throws InvalidUnitException
        Inserts a strut box (whitespace) with the given width, height and depth (in the given unit) at the end of the current TeXFormula.
        Parameters:
        unit - a unit constant (from TeXConstants)
        width - the width of the strut box
        height - the height of the strut box
        depth - the depth of the strut box
        Returns:
        the modified TeXFormula
        Throws:
        InvalidUnitException - if the given integer value does not represent a valid unit
      • addStrut

        public TeXFormula addStrut​(int type)
                            throws InvalidUnitException
        Inserts a strut box (whitespace) with the given width, height and depth (in the given unit) at the end of the current TeXFormula.
        Parameters:
        type - thinmuskip, medmuskip or thickmuskip (from TeXConstants)
        Returns:
        the modified TeXFormula
        Throws:
        InvalidUnitException - if the given integer value does not represent a valid unit
      • addStrut

        public TeXFormula addStrut​(int widthUnit,
                                   float width,
                                   int heightUnit,
                                   float height,
                                   int depthUnit,
                                   float depth)
                            throws InvalidUnitException
        Inserts a strut box (whitespace) with the given width (in widthUnits), height (in heightUnits) and depth (in depthUnits) at the end of the current TeXFormula.
        Parameters:
        widthUnit - a unit constant used for the width (from TeXConstants)
        width - the width of the strut box
        heightUnit - a unit constant used for the height (from TeXConstants)
        height - the height of the strut box
        depthUnit - a unit constant used for the depth (from TeXConstants)
        depth - the depth of the strut box
        Returns:
        the modified TeXFormula
        Throws:
        InvalidUnitException - if the given integer value does not represent a valid unit
      • createTeXIcon

        public TeXIcon createTeXIcon​(int style,
                                     float size)
        Creates a TeXIcon from this TeXFormula using the default TeXFont in the given point size and starting from the given TeX style. If the given integer value does not represent a valid TeX style, the default style TeXConstants.STYLE_DISPLAY will be used.
        Parameters:
        style - a TeX style constant (from TeXConstants) to start from
        size - the default TeXFont's point size
        Returns:
        the created TeXIcon
      • createTeXIcon

        public TeXIcon createTeXIcon​(int style,
                                     float size,
                                     int type)
      • createTeXIcon

        public TeXIcon createTeXIcon​(int style,
                                     float size,
                                     int type,
                                     java.awt.Color fgcolor)
      • createTeXIcon

        public TeXIcon createTeXIcon​(int style,
                                     float size,
                                     boolean trueValues)
      • createTeXIcon

        public TeXIcon createTeXIcon​(int style,
                                     float size,
                                     int widthUnit,
                                     float textwidth,
                                     int align)
      • createTeXIcon

        public TeXIcon createTeXIcon​(int style,
                                     float size,
                                     int type,
                                     int widthUnit,
                                     float textwidth,
                                     int align)
      • createTeXIcon

        public TeXIcon createTeXIcon​(int style,
                                     float size,
                                     int widthUnit,
                                     float textwidth,
                                     int align,
                                     int interlineUnit,
                                     float interline)
      • createTeXIcon

        public TeXIcon createTeXIcon​(int style,
                                     float size,
                                     int type,
                                     int widthUnit,
                                     float textwidth,
                                     int align,
                                     int interlineUnit,
                                     float interline)
      • createImage

        public void createImage​(java.lang.String format,
                                int style,
                                float size,
                                java.lang.String out,
                                java.awt.Color bg,
                                java.awt.Color fg,
                                boolean transparency)
      • createPNG

        public void createPNG​(int style,
                              float size,
                              java.lang.String out,
                              java.awt.Color bg,
                              java.awt.Color fg)
      • createGIF

        public void createGIF​(int style,
                              float size,
                              java.lang.String out,
                              java.awt.Color bg,
                              java.awt.Color fg)
      • createJPEG

        public void createJPEG​(int style,
                               float size,
                               java.lang.String out,
                               java.awt.Color bg,
                               java.awt.Color fg)
      • createBufferedImage

        public static java.awt.Image createBufferedImage​(java.lang.String formula,
                                                         int style,
                                                         float size,
                                                         java.awt.Color fg,
                                                         java.awt.Color bg)
                                                  throws ParseException
        Parameters:
        formula - the formula
        style - the style
        size - the size
        transparency - , if true the background is transparent
        Returns:
        the generated image
        Throws:
        ParseException
      • createBufferedImage

        public java.awt.Image createBufferedImage​(int style,
                                                  float size,
                                                  java.awt.Color fg,
                                                  java.awt.Color bg)
                                           throws ParseException
        Parameters:
        formula - the formula
        style - the style
        size - the size
        transparency - , if true the background is transparent
        Returns:
        the generated image
        Throws:
        ParseException
      • setDEBUG

        public void setDEBUG​(boolean b)
      • setBackground

        public TeXFormula setBackground​(java.awt.Color c)
        Changes the background color of the current TeXFormula into the given color. By default, a TeXFormula has no background color, it's transparent. The backgrounds of subformula's will be painted on top of the background of the whole formula! Any changes that will be made to this TeXFormula after this background color was set, will have the default background color (unless it will also be changed into another color afterwards)!
        Parameters:
        c - the desired background color for the current TeXFormula
        Returns:
        the modified TeXFormula
      • setColor

        public TeXFormula setColor​(java.awt.Color c)
        Changes the (foreground) color of the current TeXFormula into the given color. By default, the foreground color of a TeXFormula is the foreground color of the component on which the TeXIcon (created from this TeXFormula) will be painted. The color of subformula's overrides the color of the whole formula. Any changes that will be made to this TeXFormula after this color was set, will be painted in the default color (unless the color will also be changed afterwards into another color)!
        Parameters:
        c - the desired foreground color for the current TeXFormula
        Returns:
        the modified TeXFormula
      • setFixedTypes

        public TeXFormula setFixedTypes​(int leftType,
                                        int rightType)
                                 throws InvalidAtomTypeException
        Sets a fixed left and right type of the current TeXFormula. This has an influence on the glue that will be inserted before and after this TeXFormula.
        Parameters:
        leftType - atom type constant (from TeXConstants)
        rightType - atom type constant (from TeXConstants)
        Returns:
        the modified TeXFormula
        Throws:
        InvalidAtomTypeException - if the given integer value does not represent a valid atom type
      • get

        public static TeXFormula get​(java.lang.String name)
                              throws FormulaNotFoundException
        Get a predefined TeXFormula.
        Parameters:
        name - the name of the predefined TeXFormula
        Returns:
        a copy of the predefined TeXFormula
        Throws:
        FormulaNotFoundException - if no predefined TeXFormula is found with the given name