Package org.scilab.forge.jlatexmath
Class TeXParser
java.lang.Object
org.scilab.forge.jlatexmath.TeXParser
This class implements a parser for LaTeX' formulas.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTeXParser
(boolean isPartial, String parseString, ArrayOfAtoms aoa, boolean firstpass) Create a new TeXParser in the context of an array.TeXParser
(boolean isPartial, String parseString, ArrayOfAtoms aoa, boolean firstpass, boolean space) Create a new TeXParser in the context of an array.TeXParser
(boolean isPartial, String parseString, TeXFormula formula) Create a new TeXParserTeXParser
(boolean isPartial, String parseString, TeXFormula formula, boolean firstpass) Create a new TeXParser with or without a first passTeXParser
(boolean isPartial, String parseString, TeXFormula formula, boolean firstpass, boolean space) Create a new TeXParser which ignores or not the white spaces, it's useful for mbox commandTeXParser
(String parseString, ArrayOfAtoms aoa, boolean firstpass) Create a new TeXParser in the context of an array.TeXParser
(String parseString, TeXFormula formula) Create a new TeXParserTeXParser
(String parseString, TeXFormula formula, boolean firstpass) Create a new TeXParser with or without a first passTeXParser
(String parseString, TeXFormula formula, boolean firstpass, boolean space) Create a new TeXParser which ignores or not the white spaces, it's useful for mbox command -
Method Summary
Modifier and TypeMethodDescriptionvoid
Put an atom in the current formulavoid
addRow()
Add a new row when the parser is in array modeconvertCharacter
(char c, boolean oneChar) Convert a character in the corresponding atom in using the file TeXFormulaSettings.xml for non-alphanumeric charactersvoid
finish()
Get the argument of a command in his atomic formatint
getCol()
Get the number of the current columngetDollarGroup
(char openclose) Get the contents between two delimitersGet the atom represented by the current formulagetGroup
(char open, char close) Get the contents between two delimitersGet the contents between two strings as in \begin{foo}...\end{foo}boolean
Return true if we get a partial formulaGet the last atom of the current formulafloat[]
int
getLine()
Get the number of the current lineString[]
getOptsArgs
(int nbArgs, int opts) Get the arguments ant the options of a commandint
getPos()
Return the current position in the parsed stringboolean
Return a boolean indicating if the parser is used to parse an array or notboolean
Return a boolean indicating if the character @ is considered as a letter or notboolean
Return a boolean indicating if the parser must ignore white spacesboolean
Return a boolean indicating if the parser is in math modefinal boolean
isValidCharacterInCommand
(char ch) Test the validity of a character in a command.final boolean
isValidName
(String com) Test the validity of the name of a command.void
Indicate if the character @ can be used in the command's namevoid
Indicate if the character @ can be used in the command's namevoid
parse()
Parse the input stringvoid
Reset the parser with a new latex expressionint
rewind
(int n) Rewind the current parsed stringvoid
setArrayMode
(boolean arrayMode)
-
Field Details
-
isLoading
protected static boolean isLoading
-
-
Constructor Details
-
TeXParser
Create a new TeXParser- Parameters:
parseString
- the string to be parsedformula
- the formula where to put the atoms- Throws:
ParseException
- if the string could not be parsed correctly
-
TeXParser
Create a new TeXParser- Parameters:
isPartial
- if true certains exceptions are not thrownparseString
- the string to be parsedformula
- the formula where to put the atoms- Throws:
ParseException
- if the string could not be parsed correctly
-
TeXParser
Create a new TeXParser with or without a first pass- Parameters:
isPartial
- if true certains exceptions are not thrownparseString
- the string to be parsedfirstpass
- a boolean to indicate if the parser must replace the user-defined macros by their content- Throws:
ParseException
- if the string could not be parsed correctly
-
TeXParser
Create a new TeXParser with or without a first pass- Parameters:
parseString
- the string to be parsedfirstpass
- a boolean to indicate if the parser must replace the user-defined macros by their content- Throws:
ParseException
- if the string could not be parsed correctly
-
TeXParser
Create a new TeXParser in the context of an array. When the parser meets a & a new atom is added in the current line and when a \\ is met, a new line is created.- Parameters:
isPartial
- if true certains exceptions are not thrownparseString
- the string to be parsedaoa
- an ArrayOfAtoms where to put the elementsfirstpass
- a boolean to indicate if the parser must replace the user-defined macros by their content- Throws:
ParseException
- if the string could not be parsed correctly
-
TeXParser
public TeXParser(boolean isPartial, String parseString, ArrayOfAtoms aoa, boolean firstpass, boolean space) Create a new TeXParser in the context of an array. When the parser meets a & a new atom is added in the current line and when a \\ is met, a new line is created.- Parameters:
isPartial
- if true certains exceptions are not thrownparseString
- the string to be parsedaoa
- an ArrayOfAtoms where to put the elementsfirstpass
- a boolean to indicate if the parser must replace the user-defined macros by their content- Throws:
ParseException
- if the string could not be parsed correctly
-
TeXParser
Create a new TeXParser in the context of an array. When the parser meets a & a new atom is added in the current line and when a \\ is met, a new line is created.- Parameters:
parseString
- the string to be parsedaoa
- an ArrayOfAtoms where to put the elementsfirstpass
- a boolean to indicate if the parser must replace the user-defined macros by their content- Throws:
ParseException
- if the string could not be parsed correctly
-
TeXParser
public TeXParser(boolean isPartial, String parseString, TeXFormula formula, boolean firstpass, boolean space) Create a new TeXParser which ignores or not the white spaces, it's useful for mbox command- Parameters:
isPartial
- if true certains exceptions are not thrownparseString
- the string to be parsedfirstpass
- a boolean to indicate if the parser must replace the user-defined macros by their contentspace
- a boolean to indicate if the parser must ignore or not the white space- Throws:
ParseException
- if the string could not be parsed correctly
-
TeXParser
Create a new TeXParser which ignores or not the white spaces, it's useful for mbox command- Parameters:
parseString
- the string to be parsedfirstpass
- a boolean to indicate if the parser must replace the user-defined macros by their contentspace
- a boolean to indicate if the parser must ignore or not the white space- Throws:
ParseException
- if the string could not be parsed correctly
-
-
Method Details
-
reset
Reset the parser with a new latex expression -
getIsPartial
public boolean getIsPartial()Return true if we get a partial formula -
getLine
public int getLine()Get the number of the current line -
getCol
public int getCol()Get the number of the current column -
getLastAtom
Get the last atom of the current formula -
getFormulaAtom
Get the atom represented by the current formula -
addAtom
Put an atom in the current formula -
makeAtLetter
public void makeAtLetter()Indicate if the character @ can be used in the command's name -
makeAtOther
public void makeAtOther()Indicate if the character @ can be used in the command's name -
isAtLetter
public boolean isAtLetter()Return a boolean indicating if the character @ is considered as a letter or not -
isArrayMode
public boolean isArrayMode()Return a boolean indicating if the parser is used to parse an array or not -
setArrayMode
public void setArrayMode(boolean arrayMode) -
isIgnoreWhiteSpace
public boolean isIgnoreWhiteSpace()Return a boolean indicating if the parser must ignore white spaces -
isMathMode
public boolean isMathMode()Return a boolean indicating if the parser is in math mode -
getPos
public int getPos()Return the current position in the parsed string -
rewind
public int rewind(int n) Rewind the current parsed string- Parameters:
n
- the number of character to be rewinded- Returns:
- the new position in the parsed string
-
getStringFromCurrentPos
-
finish
public void finish() -
addRow
Add a new row when the parser is in array mode- Throws:
ParseException
- if the parser is not in array mode
-
parse
Parse the input string- Throws:
ParseException
- if an error is encountered during parsing
-
getDollarGroup
Get the contents between two delimiters- Parameters:
openclose
- the opening and closing character (such $)- Returns:
- the enclosed contents
- Throws:
ParseException
- if the contents are badly enclosed
-
getGroup
Get the contents between two delimiters- Parameters:
open
- the opening characterclose
- the closing character- Returns:
- the enclosed contents
- Throws:
ParseException
- if the contents are badly enclosed
-
getGroup
Get the contents between two strings as in \begin{foo}...\end{foo}- Parameters:
open
- the opening stringclose
- the closing string- Returns:
- the enclosed contents
- Throws:
ParseException
- if the contents are badly enclosed
-
getArgument
Get the argument of a command in his atomic format- Returns:
- the corresponding atom
- Throws:
ParseException
- if the argument is incorrect
-
getOverArgument
- Throws:
ParseException
-
getLength
- Throws:
ParseException
-
convertCharacter
Convert a character in the corresponding atom in using the file TeXFormulaSettings.xml for non-alphanumeric characters- Parameters:
c
- the character to be converted- Returns:
- the corresponding atom
- Throws:
ParseException
- if the character is unknown
-
getOptsArgs
Get the arguments ant the options of a command- Parameters:
nbArgs
- the number of arguments of the commandopts
- must be 1 if the options are found before the first argument and must be 2 if they must be found before the second argument- Returns:
- an array containing arguments and at the end the options are put
-
isValidName
Test the validity of the name of a command. It must contains only alpha characters and eventually a @ if makeAtletter activated- Parameters:
com
- the command's name- Returns:
- the validity of the name
-
isValidCharacterInCommand
public final boolean isValidCharacterInCommand(char ch) Test the validity of a character in a command. It must contains only alpha characters and eventually a @ if makeAtletter activated- Parameters:
com
- the command's name- Returns:
- the validity of the name
-