a LaTeX parser for JKQTMathText
More...
#include <jkqtmathtextlatexparser.h>
|
enum | tokenType {
MTTnone
,
MTTtext
,
MTTinstruction
,
MTTinstructionNewline
,
MTTinstructionVerbatim
,
MTTinstructionVerbatimVisibleSpace
,
MTTinstructionBegin
,
MTTinstructionEnd
,
MTTunderscore
,
MTThat
,
MTTdollar
,
MTTopenbrace
,
MTTclosebrace
,
MTTopenbracket
,
MTTclosebracket
,
MTTwhitespace
,
MTTampersand
,
MTThyphen
,
MTTendash
,
MTTemdash
,
MTTtilde
} |
| the token types that may arrise in the string More...
|
|
|
tokenType | getToken () |
| tokenizer for the LaTeX parser
|
|
void | giveBackToTokenizer (size_t count) |
| returns some characters to the Tokenizer
|
|
JKQTMathTextNode * | parseInstruction (bool *_foundError=nullptr, bool *getNew=nullptr) |
| parses a single instruction (including it's parameters)
|
|
JKQTMathTextNode * | parseLatexString (bool get, JKQTMathTextBraceType quitOnClosingBrace=JKQTMathTextBraceType::MTBTAny, const QString &quitOnEnvironmentEnd=QString(""), bool quitOnClosingBracket=false) |
| parse a LaTeX string
|
|
JKQTMathTextNode * | parseMath (bool get) |
| parse a LaTeX math environment
|
|
JKQTMathTextVerticalListNode * | parseMultilineLatexString (bool get, const QString &quitOnEnvironmentEnd=QString(""), JKQTMathTextHorizontalAlignment _alignment=MTHALeft, double _linespacingFactor=1.0, JKQTMathTextLineSpacingMode spacingMode_=MTSMDefaultSpacing, JKQTMathTextVerticalOrientation _verticalOrientation=MTVOFirstLine) |
| parse a LaTeX string with linebreaks
|
|
QString | parseSingleString (bool get) |
| parses a string, i.e. a sequence of text and whitespaces. returns after any other token was found
|
|
QStringList | parseStringParams (bool get, size_t Nparams, bool *foundError=nullptr) |
| parses a list of string-arguments, i.e. {p1}{p2}{ ...}
|
|
QString | readUntil (bool get, const QString &endsequence, bool removeFirstlineWhitespace=false) |
| read all text without tokenizing, until the sequence endsequence is found.
|
|
void | addToErrorList (const QString &error) |
| adds a new error to the JKQTMathText referenced by parentMathText
|
|
void | clearErrorList () |
| clears the error list in the JKQTMathText referenced by parentMathText
|
|
a LaTeX parser for JKQTMathText
JKQTMathText is a self-contained mathematical markup renderer for Qt. It is used to renderer labels in JKQTPlotter/JKQTBasePlotter, but can be used independently.
That class is responsible for rendering a memory representation of mathematical markup, but relies on the current class JKQTMathTextLatexParser to parse a LaTeX string into the mentioned memory representation.
- See also
- See Supported LaTeX-Subset for a description of the supported LaTeX subset and JKQTMathText Rendering Model for a description of the rendering model.
In particular JKQTMathTextLatexParser actually parses e.g. a LaTeX string and draws it in pure C++. It does NOT rely on an installed LaTeX for the rendering!
◆ tokenType
the token types that may arrise in the string
Enumerator |
---|
MTTnone | no token
|
MTTtext | a piece of general text
|
MTTinstruction | an instruction, started by "\", e.g. \c "\textbf" , ...
|
MTTinstructionNewline | a newline instruction "\\"
|
MTTinstructionVerbatim | a verbatim instruction, e.g. \verb!verbatimtext! was found: currentTokenName will contain the text enclode by the verbatim delimiters
|
MTTinstructionVerbatimVisibleSpace | a verbatim instruction that generates visible whitespaces, e.g. \begin{verbatim} ...\end{verbatim} was found: currentTokenName will contain the text enclode by the verbatim delimiters
|
MTTinstructionBegin | a '\begin{ ...}' instruction, currentTokenName is the name of the environment
|
MTTinstructionEnd | a '\end{ ...}' instruction, currentTokenName is the name of the environment
|
MTTunderscore | the character "_"
|
MTThat | the character "^"
|
MTTdollar | the character "$"
|
MTTopenbrace | the character "{"
|
MTTclosebrace | the character "}"
|
MTTopenbracket | the character "["
|
MTTclosebracket | the character "]"
|
MTTwhitespace | some whitespace
|
MTTampersand | the character "&"
|
MTThyphen | the single hyphen character "-" in text-mode
- Note
- MTTendash and MTTemdash take precedence over MTThypen
|
MTTendash | the en-dash character sequence "--" in text-mode
|
MTTemdash | the em-dash character sequence "---" in text-mode
|
MTTtilde | the tilde character "~"
|
◆ JKQTMathTextLatexParser()
JKQTMathTextLatexParser::JKQTMathTextLatexParser |
( |
JKQTMathText * |
parent = nullptr | ) |
|
◆ ~JKQTMathTextLatexParser()
JKQTMathTextLatexParser::~JKQTMathTextLatexParser |
( |
| ) |
|
◆ getToken()
tokenType JKQTMathTextLatexParser::getToken |
( |
| ) |
|
|
protected |
tokenizer for the LaTeX parser
◆ giveBackToTokenizer()
void JKQTMathTextLatexParser::giveBackToTokenizer |
( |
size_t |
count | ) |
|
|
protected |
returns some characters to the Tokenizer
◆ initStaticStructures()
static void JKQTMathTextLatexParser::initStaticStructures |
( |
| ) |
|
|
staticprotected |
fills all static data structures, if they are still empty
◆ parse()
parse the given mathematical markup string.
- Parameters
-
text | the markup to be parsed |
options | Options for parsing, |
- See also
- ParseOptions
- Returns
- the memory representation of the markup
nullptr
on failure.
Implements JKQTMathTextParser.
◆ parseInstruction()
JKQTMathTextNode * JKQTMathTextLatexParser::parseInstruction |
( |
bool * |
_foundError = nullptr , |
|
|
bool * |
getNew = nullptr |
|
) |
| |
|
protected |
parses a single instruction (including it's parameters)
- Parameters
-
[out] | _foundError | will be set to true if an error occured (unexpected token) or false otherwise |
[out] | getNew | returns true if the parser has to call getToken() to go on |
- Returns
- the instruction node or
nullptr
on error (then also _foundError is set true
)
- Note
- This method expects the current token currentToken to be MTTinstruction
◆ parseLatexString()
parse a LaTeX string
- Parameters
-
get | if true this calls getToken() |
quitOnClosingBrace | if unequal MTBTAny, this returns if the given closing brace is found |
quitOnEnvironmentEnd | wuit if \end{quitOnEnvironmentEnd} is found |
quitOnClosingBracket | if true , quits on encountering a MTTclosebracket token |
◆ parseMath()
parse a LaTeX math environment
◆ parseMultilineLatexString()
◆ parseSingleString()
QString JKQTMathTextLatexParser::parseSingleString |
( |
bool |
get | ) |
|
|
protected |
parses a string, i.e. a sequence of text and whitespaces. returns after any other token was found
◆ parseStringParams()
QStringList JKQTMathTextLatexParser::parseStringParams |
( |
bool |
get, |
|
|
size_t |
Nparams, |
|
|
bool * |
foundError = nullptr |
|
) |
| |
|
protected |
parses a list of string-arguments, i.e. {p1}{p2}{
...}
- Parameters
-
| get | call getToken() at the start, otherwise it is expected that currentToken==MTTopenbrace |
| Nparams | the number of parameters to expect |
[out] | foundError | will be set to true if an error occured (unexpected token) or false otherwise |
- Returns
- the list of parameter strings with Nparam entries or an empty or partial list on error
◆ readUntil()
QString JKQTMathTextLatexParser::readUntil |
( |
bool |
get, |
|
|
const QString & |
endsequence, |
|
|
bool |
removeFirstlineWhitespace = false |
|
) |
| |
|
protected |
read all text without tokenizing, until the sequence endsequence is found.
- Parameters
-
get | if true the functions begins by reading a new character, otherwise the current character is used as first character |
endsequence | the sequence, ending the read |
removeFirstlineWhitespace | if true the returned string does not contain the first whitespace-line and a possible trailing whitespace line |
- Returns
- the read string, excluding the endsequence
◆ tokenType2String()
static QString JKQTMathTextLatexParser::tokenType2String |
( |
tokenType |
type | ) |
|
|
staticprotected |
convert a tokenType into a string, e.g. for debugging output
◆ accentLetters
QHash<QString, QChar> JKQTMathTextLatexParser::accentLetters |
|
staticprotected |
maps instructions for accents in text-mode (e.g. \'a
or \ae
) to the corresponding unicode character
◆ accentLetters_LenBackslash
QSet<int> JKQTMathTextLatexParser::accentLetters_LenBackslash |
|
staticprotected |
lists all lengths of keys in accentLetters that start with a backslash
◆ accentLetters_LenCurly
QSet<int> JKQTMathTextLatexParser::accentLetters_LenCurly |
|
staticprotected |
lists all lengths of keys in accentLetters that start with a curly brace
◆ big_instructions_family
QHash<QString,double> JKQTMathTextLatexParser::big_instructions_family |
|
staticprotected |
maps instructions for braces with fixed size, e.g \bigl
to the magnification factor of the brace versus the base font
◆ currentToken
tokenType JKQTMathTextLatexParser::currentToken |
|
protected |
used by the tokenizer. type of the current token
◆ currentTokenID
int JKQTMathTextLatexParser::currentTokenID |
|
protected |
used by the tokenizer. Points to the currently read character in parseString
◆ currentTokenName
QString JKQTMathTextLatexParser::currentTokenName |
|
protected |
used by the tokenizer. Name of the current token, id applicable
◆ lastMatrixLineCommandCount
QMap<QString,size_t> JKQTMathTextLatexParser::lastMatrixLineCommandCount |
|
protected |
returns the number of \hline
, \hdashline
, ... commands in the last parseLatexString() call
◆ lastRightBraceType
the JKQTMathTextBraceType associated with the last \right
command the parser encountered
◆ mathEnvironmentSpecialChars
QSet<QChar> JKQTMathTextLatexParser::mathEnvironmentSpecialChars |
|
staticprotected |
characters that require special treatment in math mode
◆ mathEnvironmentSpecialEndChars
QSet<QChar> JKQTMathTextLatexParser::mathEnvironmentSpecialEndChars |
|
staticprotected |
characters that require special treatment in math mode
◆ mathEnvironmentSpecialText
QSet<QString> JKQTMathTextLatexParser::mathEnvironmentSpecialText |
|
staticprotected |
◆ parseString
QString JKQTMathTextLatexParser::parseString |
|
protected |
used by the tokenizer. The string to be parsed
◆ parsinginMathTextStyle
bool JKQTMathTextLatexParser::parsinginMathTextStyle |
|
protected |
used by the parser. indicates whether to use textstyle or displaystyle in math-mode
◆ parsingMathEnvironment
bool JKQTMathTextLatexParser::parsingMathEnvironment |
|
protected |
used by the parser. indicates whether we are in a math environment
◆ SingleCharInstructions
QSet<QChar> JKQTMathTextLatexParser::SingleCharInstructions |
|
staticprotected |
single character instructions
◆ TokenCharacters
QSet<QChar> JKQTMathTextLatexParser::TokenCharacters |
|
staticprotected |
characters that initiate a new token
The documentation for this class was generated from the following file: