JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches

a LaTeX parser for JKQTMathText More...

#include <jkqtmathtextlatexparser.h>

Inheritance diagram for JKQTMathTextLatexParser:
[legend]
Collaboration diagram for JKQTMathTextLatexParser:
[legend]

Public Member Functions

 JKQTMathTextLatexParser (JKQTMathText *parent=nullptr)
 class constructor
 
 ~JKQTMathTextLatexParser ()
 class destructor
 
virtual JKQTMathTextNodeparse (const QString &text, JKQTMathText::ParseOptions options=JKQTMathText::DefaultParseOptions) override
 parse the given mathematical markup string.
 
- Public Member Functions inherited from JKQTMathTextParser
 JKQTMathTextParser (JKQTMathText *parent=nullptr)
 class constructor
 
virtual ~JKQTMathTextParser ()
 class destructor
 
JKQTMathTextgetParentMathText ()
 parentMathText
 
const JKQTMathTextgetParentMathText () const
 parentMathText
 

Protected Types

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...
 

Protected Member Functions

tokenType getToken ()
 tokenizer for the LaTeX parser
 
void giveBackToTokenizer (size_t count)
 returns some characters to the Tokenizer
 
JKQTMathTextNodeparseInstruction (bool *_foundError=nullptr, bool *getNew=nullptr)
 parses a single instruction (including it's parameters)
 
JKQTMathTextNodeparseLatexString (bool get, JKQTMathTextBraceType quitOnClosingBrace=JKQTMathTextBraceType::MTBTAny, const QString &quitOnEnvironmentEnd=QString(""), bool quitOnClosingBracket=false)
 parse a LaTeX string
 
JKQTMathTextNodeparseMath (bool get)
 parse a LaTeX math environment
 
JKQTMathTextVerticalListNodeparseMultilineLatexString (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.
 
- Protected Member Functions inherited from JKQTMathTextParser
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
 

Static Protected Member Functions

static void initStaticStructures ()
 fills all static data structures, if they are still empty
 
static QString tokenType2String (tokenType type)
 convert a tokenType into a string, e.g. for debugging output
 

Protected Attributes

tokenType currentToken
 used by the tokenizer. type of the current token
 
int currentTokenID
 used by the tokenizer. Points to the currently read character in parseString
 
QString currentTokenName
 used by the tokenizer. Name of the current token, id applicable
 
QMap< QString, size_t > lastMatrixLineCommandCount
 returns the number of \hline , \hdashline , ... commands in the last parseLatexString() call
 
JKQTMathTextBraceType lastRightBraceType
 the JKQTMathTextBraceType associated with the last \right command the parser encountered
 
QString parseString
 used by the tokenizer. The string to be parsed
 
bool parsinginMathTextStyle
 used by the parser. indicates whether to use textstyle or displaystyle in math-mode
 
bool parsingMathEnvironment
 used by the parser. indicates whether we are in a math environment
 
- Protected Attributes inherited from JKQTMathTextParser
JKQTMathTextparentMathText
 JKQTMathText that instanciated and uses this parser.
 

Static Protected Attributes

static QHash< QString, QChar > accentLetters
 maps instructions for accents in text-mode (e.g. \'a or \ae ) to the corresponding unicode character
 
static QSet< int > accentLetters_LenBackslash
 lists all lengths of keys in accentLetters that start with a backslash
 
static QSet< int > accentLetters_LenCurly
 lists all lengths of keys in accentLetters that start with a curly brace
 
static QHash< QString, double > big_instructions_family
 maps instructions for braces with fixed size, e.g \bigl to the magnification factor of the brace versus the base font
 
static QSet< QChar > mathEnvironmentSpecialChars
 characters that require special treatment in math mode
 
static QSet< QChar > mathEnvironmentSpecialEndChars
 characters that require special treatment in math mode
 
static QSet< QString > mathEnvironmentSpecialText
 characters that have to be replaced by the correspcoting JKQTMathTextSymbolNode in math mode
 
static QSet< QChar > SingleCharInstructions
 single character instructions
 
static QSet< QChar > TokenCharacters
 characters that initiate a new token
 

Detailed Description

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!

Member Enumeration Documentation

◆ 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 "~"

Constructor & Destructor Documentation

◆ JKQTMathTextLatexParser()

JKQTMathTextLatexParser::JKQTMathTextLatexParser ( JKQTMathText parent = nullptr)

class constructor

◆ ~JKQTMathTextLatexParser()

JKQTMathTextLatexParser::~JKQTMathTextLatexParser ( )

class destructor

Member Function Documentation

◆ 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()

virtual JKQTMathTextNode * JKQTMathTextLatexParser::parse ( const QString &  text,
JKQTMathText::ParseOptions  options = JKQTMathText::DefaultParseOptions 
)
overridevirtual

parse the given mathematical markup string.

Parameters
textthe markup to be parsed
optionsOptions 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]_foundErrorwill be set to true if an error occured (unexpected token) or false otherwise
[out]getNewreturns 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()

JKQTMathTextNode * JKQTMathTextLatexParser::parseLatexString ( bool  get,
JKQTMathTextBraceType  quitOnClosingBrace = JKQTMathTextBraceType::MTBTAny,
const QString &  quitOnEnvironmentEnd = QString(""),
bool  quitOnClosingBracket = false 
)
protected

parse a LaTeX string

Parameters
getif true this calls getToken()
quitOnClosingBraceif unequal MTBTAny, this returns if the given closing brace is found
quitOnEnvironmentEndwuit if \end{quitOnEnvironmentEnd} is found
quitOnClosingBracketif true, quits on encountering a MTTclosebracket token

◆ parseMath()

JKQTMathTextNode * JKQTMathTextLatexParser::parseMath ( bool  get)
protected

parse a LaTeX math environment

◆ parseMultilineLatexString()

JKQTMathTextVerticalListNode * JKQTMathTextLatexParser::parseMultilineLatexString ( bool  get,
const QString &  quitOnEnvironmentEnd = QString(""),
JKQTMathTextHorizontalAlignment  _alignment = MTHALeft,
double  _linespacingFactor = 1.0,
JKQTMathTextLineSpacingMode  spacingMode_ = MTSMDefaultSpacing,
JKQTMathTextVerticalOrientation  _verticalOrientation = MTVOFirstLine 
)
protected

parse a LaTeX string with linebreaks

Parameters
getif true this calls getToken()
quitOnEnvironmentEndwuit if \end{quitOnEnvironmentEnd} is found
_alignmenthorizontal alignment of the JKQTMathTextVerticalListNode
See also
JKQTMathTextVerticalListNode::alignment and JKQTMathTextHorizontalAlignment
Parameters
_linespacingFactorline spacing factor of the lines
See also
JKQTMathTextVerticalListNode::linespacingFactor
Parameters
spacingMode_spacing mode/algorithm for the lines
See also
JKQTMathTextLineSpacingMode and JKQTMathTextLineSpacingMode
Parameters
_verticalOrientationvertical orientation of the block of all lines, see JKQTMathTextVerticalListNode::verticalOrientation and JKQTMathTextVerticalOrientation
Returns
JKQTMathTextVerticalListNode with the lines as children

◆ 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
getcall getToken() at the start, otherwise it is expected that currentToken==MTTopenbrace
Nparamsthe number of parameters to expect
[out]foundErrorwill 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
getif true the functions begins by reading a new character, otherwise the current character is used as first character
endsequencethe sequence, ending the read
removeFirstlineWhitespaceif 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

Member Data Documentation

◆ 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

JKQTMathTextBraceType JKQTMathTextLatexParser::lastRightBraceType
protected

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

characters that have to be replaced by the correspcoting JKQTMathTextSymbolNode in math mode

◆ 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: