@@ -65,6 +65,7 @@ enum eKeywordId {
6565 KEYWORD_newcommand ,
6666 KEYWORD_renewcommand ,
6767 KEYWORD_providecommand ,
68+ KEYWORD_def ,
6869 KEYWORD_newcounter ,
6970};
7071typedef int keywordId ; /* to allow KEYWORD_NONE */
@@ -173,6 +174,7 @@ static const keywordTable TexKeywordTable [] = {
173174 { "newcommand" , KEYWORD_newcommand },
174175 { "renewcommand" , KEYWORD_renewcommand },
175176 { "providecommand" , KEYWORD_providecommand },
177+ { "def" , KEYWORD_def },
176178 { "newcounter" , KEYWORD_newcounter },
177179};
178180
@@ -606,13 +608,13 @@ static bool parseWithStrategy (tokenInfo *token,
606608 }
607609 else if (s -> type == '*' && isType (token , '*' ))
608610 next_token = true;
609- else if (s -> type == '{' && isType (token , '{' ))
611+ else if (( s -> type == '{' && isType (token , '{' )) || ( s -> type == '\\' && isType ( token , TOKEN_IDENTIFIER ) ))
610612 {
611613 int depth = 1 ;
612614
613615 next_token = true;
614616
615- if (!readToken (token ))
617+ if (s -> type == '{' && !readToken (token ))
616618 {
617619 eof = true;
618620 break ;
@@ -622,6 +624,11 @@ static bool parseWithStrategy (tokenInfo *token,
622624 copyToken (name , token );
623625 vStringClear (name -> string );
624626 }
627+ if (s -> type == '\\' )
628+ {
629+ vStringCat (name -> string , token -> string );
630+ depth = 0 ;
631+ }
625632
626633 /* Handle the case the code like \section{} */
627634 if (isType (token , '}' ))
@@ -845,6 +852,37 @@ static bool parseNewcommand (tokenInfo *const token, bool *tokenUnprocessed)
845852 return eof ;
846853}
847854
855+ static bool parseDef (tokenInfo * const token , bool * tokenUnprocessed )
856+ {
857+ bool eof = false;
858+
859+ /* \def\cmd{replacement} */
860+ struct TexParseStrategy strategy [] = {
861+ {
862+ .type = '\\' ,
863+ .flags = 0 ,
864+ .kindIndex = TEXTAG_COMMAND ,
865+ .roleIndex = ROLE_DEFINITION_INDEX ,
866+ .name = NULL ,
867+ .unique = false,
868+ },
869+ {
870+ .type = '{' ,
871+ .flags = 0 ,
872+ .kindIndex = KIND_GHOST_INDEX ,
873+ .name = NULL ,
874+ },
875+ {
876+ .type = 0
877+ }
878+ };
879+
880+ if (parseWithStrategy (token , strategy , tokenUnprocessed ))
881+ eof = true;
882+
883+ return eof ;
884+ }
885+
848886static bool parseNewcounter (tokenInfo * const token , bool * tokenUnprocessed )
849887{
850888 bool eof = false;
@@ -942,6 +980,9 @@ static void parseTexFile (tokenInfo *const token)
942980 case KEYWORD_providecommand :
943981 eof = parseNewcommand (token , & tokenUnprocessed );
944982 break ;
983+ case KEYWORD_def :
984+ eof = parseDef (token , & tokenUnprocessed );
985+ break ;
945986 case KEYWORD_newcounter :
946987 eof = parseNewcounter (token , & tokenUnprocessed );
947988 break ;
0 commit comments