From b2ad2ef1387571c7b917a7fd63e8670582ae8b7f Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 4 Jan 2005 22:30:59 +0000 Subject: in with the new --- src/cmd/delatex.lx | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/cmd/delatex.lx (limited to 'src/cmd/delatex.lx') diff --git a/src/cmd/delatex.lx b/src/cmd/delatex.lx new file mode 100644 index 00000000..063aa7dc --- /dev/null +++ b/src/cmd/delatex.lx @@ -0,0 +1,64 @@ +/* Make this with: lex delatex.lex; cc lex.yy.c -ll -o delatex */ +L [A-Za-z] +%Start Display Math Normal Tag +%% +\' {yyleng--; yymore(); /* ignore apostrophes */} +{L}+\\- {yyleng-=2; yymore(); /* ignore hyphens */} +[a-z]/[^A-Za-z] ; /* ignore single letter "words" */ +[A-Z]+ ; /* ignore words all in uppercase */ +{L}+('{L}*)*{L} {printf("%s\n",yytext); /* any other letter seq is a word */} +"%".* ; /* ignore comments */ +\\{L}+ ; /* ignore other control sequences */ +"\\begin{" BEGIN Tag; /* ignore this and up to next "}" */ +"\\bibitem{" BEGIN Tag; +"\\bibliography{" BEGIN Tag; +"\\bibstyle{" BEGIN Tag; +"\\cite{" BEGIN Tag; +"\\end{" BEGIN Tag; +"\\include{" BEGIN Tag; +"\\includeonly{" BEGIN Tag; +"\\input{" BEGIN Tag; +"\\label{" BEGIN Tag; +"\\pageref{" BEGIN Tag; +"\\ref{" BEGIN Tag; +[^}] ; /* ignore things up to next "}" */ +"}" BEGIN Normal; +[0-9]+ ; /* ignore numbers */ +"\\(" BEGIN Math; /* begin latex math mode */ +"\\)" BEGIN Normal; /* end latex math mode */ +.|\\[^)]|\n ; /* ignore anything else in latex math mode */ +"\\[" BEGIN Display; /* now in Latex display mode */ +[^$]|\\[^\]] ; /* ignore most things in display math mode */ +"\\]" BEGIN Normal; /* get out of Display math mode */ +\\. ; /* ignore other single character control sequences */ +\\\n ; /* more of the same */ +\n|. ; /* ignore anything else, a character at a time */ +%% +#include +#include + +int +main(int argc, char **argv) +{ + int i; + + BEGIN Normal; /* Starts yylex off in the right state */ + if (argc==1) { + yyin = stdin; + yylex(); + } + else for (i=1; i