/* Make this with: lex delatex.lex; cc lex.yy.c -ll -o delatex */ L [A-Za-z] %Start Display Math Normal Tag VerbPlus Bracket %% \' {yyleng--; yymore(); /* ignore apostrophes */} {L}+\\- {yyleng-=2; yymore(); /* ignore hyphens */} [a-zA-Z0-9_]+@[a-zA-Z0-9_.]+ ; /* ignore email addresses */ [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; "\\verb+" BEGIN VerbPlus; "\\documentclass[" BEGIN Bracket; "\\documentclass{" BEGIN Tag; "\\usepackage[" BEGIN Bracket; "\\usepackage{" BEGIN Tag; [^\]] ; "][" ; "]{" BEGIN Tag; "]" BEGIN Normal; [^}] ; /* ignore things up to next "}" */ "}" BEGIN Normal; [^+] ; /* ignore thing 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; if (argc==1) { yyin = stdin; BEGIN Normal; /* Starts yylex off in the right state */ yylex(); } else for (i=1; i