Skip to content

Commit 952983d

Browse files
committed
Tex: Parse \DeclareMathOperator{cmd}{def}
1 parent 04d5c98 commit 952983d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Units/parser-tex.r/newcommand.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
\\mysection0 input.tex /^\\newcommand{\\mysection0}{\\section{#1}}$/;" C
55
\\mysection1 input.tex /^\\newcommand{\\mysection1}[1]{\\section{#1}}$/;" C
66
\\mysection2 input.tex /^\\newcommand{\\mysection2}[1][1]{\\section{#1}}$/;" C
7+
\\op input.tex /^\\DeclareMathOperator{\\op}{foo}$/;" o

Units/parser-tex.r/newcommand.d/input.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
\renewcommand{\foo}{\section{#1}}
66
\providecommand{\bar}{\section{#1}}
77
\def\baz{\section{#1}}
8+
\DeclareMathOperator{\op}{foo}
89
\begin{document}
910
\mysection0{ABC}
1011
\mysection1{EFG}

parsers/tex.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ enum eKeywordId {
6666
KEYWORD_renewcommand,
6767
KEYWORD_providecommand,
6868
KEYWORD_def,
69+
KEYWORD_declaremathoperator,
6970
KEYWORD_newcounter,
7071
};
7172
typedef int keywordId; /* to allow KEYWORD_NONE */
@@ -120,6 +121,7 @@ typedef enum {
120121
TEXTAG_XINPUT,
121122
TEXTAG_BIBITEM,
122123
TEXTAG_COMMAND,
124+
TEXTAG_OPERATOR,
123125
TEXTAG_COUNTER,
124126
TEXTAG_COUNT
125127
} texKind;
@@ -152,6 +154,7 @@ static kindDefinition TexKinds [] = {
152154
.referenceOnly = true, ATTACH_ROLES(TexInputRoles) },
153155
{ true, 'B', "bibitem", "bibliography items" },
154156
{ true, 'C', "command", "command created with \\newcommand" },
157+
{ true, 'o', "operator", "math operator created with \\DeclareMathOperator" },
155158
{ true, 'N', "counter", "counter created with \\newcounter" },
156159
};
157160

@@ -175,6 +178,7 @@ static const keywordTable TexKeywordTable [] = {
175178
{ "renewcommand", KEYWORD_renewcommand },
176179
{ "providecommand", KEYWORD_providecommand },
177180
{ "def", KEYWORD_def },
181+
{ "DeclareMathOperator", KEYWORD_declaremathoperator },
178182
{ "newcounter", KEYWORD_newcounter },
179183
};
180184

@@ -809,7 +813,7 @@ static bool parseEnv (tokenInfo *const token, bool begin, bool *tokenUnprocessed
809813

810814
}
811815

812-
static bool parseNewcommand (tokenInfo *const token, bool *tokenUnprocessed)
816+
static bool parseNewcommandFull (tokenInfo *const token, bool *tokenUnprocessed, texKind kind)
813817
{
814818
bool eof = false;
815819

@@ -818,7 +822,7 @@ static bool parseNewcommand (tokenInfo *const token, bool *tokenUnprocessed)
818822
{
819823
.type = '{',
820824
.flags = 0,
821-
.kindIndex = TEXTAG_COMMAND,
825+
.kindIndex = kind,
822826
.roleIndex = ROLE_DEFINITION_INDEX,
823827
.name = NULL,
824828
.unique = false,
@@ -852,6 +856,11 @@ static bool parseNewcommand (tokenInfo *const token, bool *tokenUnprocessed)
852856
return eof;
853857
}
854858

859+
static bool parseNewcommand (tokenInfo *const token, bool *tokenUnprocessed)
860+
{
861+
return parseNewcommandFull (token, tokenUnprocessed, TEXTAG_COMMAND);
862+
}
863+
855864
static bool parseDef (tokenInfo *const token, bool *tokenUnprocessed)
856865
{
857866
bool eof = false;
@@ -983,6 +992,9 @@ static void parseTexFile (tokenInfo *const token)
983992
case KEYWORD_def:
984993
eof = parseDef (token, &tokenUnprocessed);
985994
break;
995+
case KEYWORD_declaremathoperator:
996+
eof = parseNewcommandFull (token, &tokenUnprocessed, TEXTAG_OPERATOR);
997+
break;
986998
case KEYWORD_newcounter:
987999
eof = parseNewcounter (token, &tokenUnprocessed);
9881000
break;

0 commit comments

Comments
 (0)