/* Make this with: lex detex.lex; cc lex.yy.c -ll -o detex */ L [A-Za-z}{|\]\[\\] %Start Display Normal %% \' {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 single character control sequences */ !\n ; /* more of the same */ "%".* ; /* ignore comments */ !{L}+ ; /* ignore other control sequences */ [0-9]+ ; /* ignore numbers */ \$([^$]|!\$)+\$ ; /* ignore things in math mode */ \$\$ BEGIN Display; /* now in Display math mode */ [^$]|!\$|!! ; /* ignore most things in display math mode */ \$\$ BEGIN Normal; /* get out of Display math mode */ \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