From 17be5934e0302af7849d7704123b7ff0425f71bf Mon Sep 17 00:00:00 2001 From: Mino1289 Date: Fri, 22 Oct 2021 23:44:10 +0200 Subject: [PATCH] [apps/reader] Ajout du support de \sqrt[n]{x} dans le parser LaTeX --- apps/reader/tex_parser.cpp | 28 ++++++++++++++++++++++++---- apps/reader/tex_parser.h | 2 ++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/apps/reader/tex_parser.cpp b/apps/reader/tex_parser.cpp index 5cd229ace..d36eee6ff 100644 --- a/apps/reader/tex_parser.cpp +++ b/apps/reader/tex_parser.cpp @@ -21,12 +21,12 @@ Layout TexParser::getLayout() { return layout; } -Layout TexParser::popBlock(char block) { +Layout TexParser::popBlock() { while (*m_text == ' ') { m_text ++; } - if (*m_text == block) { + if (*m_text == '}') { m_text ++; return popText('}'); } @@ -98,12 +98,32 @@ Layout TexParser::popCommand() { return popFracCommand(); } } + else if (strcmp(k_sqrtCommand, m_text, strlen(k_fracCommand)) == 0) { + m_text += strlen(k_fracCommand); + if (*m_text == ' ' || *m_text == '{' || *m_text == '[') { + return popSqrtCommand(); + } + } + return popFracCommand(); } +Layout TexParser::popSqrtCommand() { + while (*m_text == ' ') { + m_text ++; + } + m_text++; + if (*m_text == '[') { + return NthRootLayout::Builder(popText(']'),popBlock()); + } + else { + return NthRootLayout::Builder(popBlock()); + } +} + Layout TexParser::popFracCommand() { - Layout firstBlock = popBlock('{'); - Layout secondBlock = popBlock('{'); + Layout firstBlock = popBlock(); + Layout secondBlock = popBlock(); return FractionLayout::Builder(firstBlock, secondBlock); } diff --git a/apps/reader/tex_parser.h b/apps/reader/tex_parser.h index 6119a1403..5ae470eba 100644 --- a/apps/reader/tex_parser.h +++ b/apps/reader/tex_parser.h @@ -19,11 +19,13 @@ private: Layout popText(char stop); Layout popCommand(); Layout popFracCommand(); + Layout popSqrtCommand(); const char * m_text; const char * m_endOfText; bool m_hasError; static constexpr char const * k_fracCommand = "frac"; + static constexpr char const * k_sqrtCommand = "sqrt"; }; }