blob: 04f2480c0c398f16bda523110b71e5e97ccfad5a [file] [log] [blame]
rscb2ad2ef2005-01-04 22:30:59 +00001/* Make this with: lex delatex.lex; cc lex.yy.c -ll -o delatex */
2L [A-Za-z]
rscb8e710d2005-01-30 16:48:14 +00003%Start Display Math Normal Tag VerbPlus Bracket
rscb2ad2ef2005-01-04 22:30:59 +00004%%
5<Normal>\' {yyleng--; yymore(); /* ignore apostrophes */}
6<Normal>{L}+\\- {yyleng-=2; yymore(); /* ignore hyphens */}
rscb8e710d2005-01-30 16:48:14 +00007<Normal>[a-zA-Z0-9_]+@[a-zA-Z0-9_.]+ ; /* ignore email addresses */
rscb2ad2ef2005-01-04 22:30:59 +00008<Normal>[a-z]/[^A-Za-z] ; /* ignore single letter "words" */
9<Normal>[A-Z]+ ; /* ignore words all in uppercase */
10<Normal>{L}+('{L}*)*{L} {printf("%s\n",yytext); /* any other letter seq is a word */}
11<Normal>"%".* ; /* ignore comments */
12<Normal>\\{L}+ ; /* ignore other control sequences */
13<Normal>"\\begin{" BEGIN Tag; /* ignore this and up to next "}" */
14<Normal>"\\bibitem{" BEGIN Tag;
15<Normal>"\\bibliography{" BEGIN Tag;
16<Normal>"\\bibstyle{" BEGIN Tag;
17<Normal>"\\cite{" BEGIN Tag;
18<Normal>"\\end{" BEGIN Tag;
19<Normal>"\\include{" BEGIN Tag;
20<Normal>"\\includeonly{" BEGIN Tag;
21<Normal>"\\input{" BEGIN Tag;
22<Normal>"\\label{" BEGIN Tag;
23<Normal>"\\pageref{" BEGIN Tag;
24<Normal>"\\ref{" BEGIN Tag;
rscb8e710d2005-01-30 16:48:14 +000025<Normal>"\\verb+" BEGIN VerbPlus;
26<Normal>"\\documentclass[" BEGIN Bracket;
27<Normal>"\\documentclass{" BEGIN Tag;
28<Normal>"\\usepackage[" BEGIN Bracket;
29<Normal>"\\usepackage{" BEGIN Tag;
30<Bracket>[^\]] ;
31<Bracket>"][" ;
32<Bracket>"]{" BEGIN Tag;
33<Bracket>"]" BEGIN Normal;
rscb2ad2ef2005-01-04 22:30:59 +000034<Tag>[^}] ; /* ignore things up to next "}" */
35<Tag>"}" BEGIN Normal;
rscb8e710d2005-01-30 16:48:14 +000036<VerbPlus>[^+] ; /* ignore thing up to next "+" */
37<VerbPlus>"+" BEGIN Normal;
rscb2ad2ef2005-01-04 22:30:59 +000038<Normal>[0-9]+ ; /* ignore numbers */
39<Normal>"\\(" BEGIN Math; /* begin latex math mode */
40<Math>"\\)" BEGIN Normal; /* end latex math mode */
41<Math>.|\\[^)]|\n ; /* ignore anything else in latex math mode */
42<Normal>"\\[" BEGIN Display; /* now in Latex display mode */
43<Display>[^$]|\\[^\]] ; /* ignore most things in display math mode */
44<Display>"\\]" BEGIN Normal; /* get out of Display math mode */
45<Normal>\\. ; /* ignore other single character control sequences */
46<Normal>\\\n ; /* more of the same */
47<Normal>\n|. ; /* ignore anything else, a character at a time */
48%%
49#include <stdio.h>
50#include <stdlib.h>
51
52int
53main(int argc, char **argv)
54{
55 int i;
56
57 BEGIN Normal; /* Starts yylex off in the right state */
58 if (argc==1) {
59 yyin = stdin;
60 yylex();
61 }
62 else for (i=1; i<argc; i++) {
63 yyin = fopen(argv[i],"r");
64 if (yyin==NULL) {
65 fprintf(stderr,"can't open %s\n",argv[i]);
66 exit(1);
67 }
68 yylex();
69 }
70 exit(0);
71}
72int
73yywrap(void)
74{
75 return 1;
76}