/* 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; !documentstyle[\<\(] 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 */ \$([^$]|!\$)+\$ ; /* ignore things in math mode */ "![" BEGIN Display; /* now in Latex display mode */ "$$" BEGIN Display; /* now in Display math mode */ [^$]|![^\]] ; /* ignore most things in display math mode */ "!]" BEGIN Normal; /* get out of 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 */ %% main(argc,argv) char **argv; { int i; BEGIN Normal; /* Starts yylex off in the right state */ if (argc==1) { yyin = stdin; yylex(); } else for (i=1; i