start condition for TeX equations [closed]

你离开我真会死。 提交于 2019-12-11 11:46:14

问题


In lex, I can define the following starting condition for equations defined between $...$.

%x EQN1

\$ { BEGIN(EQN1); }
<EQN1>{
    \$ { BEGIN(INITIAL); }
    [^\$]* {} 
}

For equations between $$...$$, how can I define the anything but $$ rule, such as in [^\$]*. I guess [^\$\$]* wouldn't work.


回答1:


I think you don't understand the way the patterns are matched, see flex manual

Flex always try to match longest input possible. You can understand it in way, that longer rules have higher priority.

Because "\$\$" match two characters and "." just one, the example below will work just fine.

%x EQN2

\$\$ { BEGIN(EQN2); }
<EQN2>{
    \$\$ { BEGIN(INITIAL); }
    . {} 
}

You can also replace [^\$]* {} with . {} in your example, because when rules match same size of input, the first one in lex.l has higher priority.



来源:https://stackoverflow.com/questions/14843564/start-condition-for-tex-equations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!