Blob


1 /* Make this with: lex delatex.lex; cc lex.yy.c -ll -o delatex */
2 L [A-Za-z]
3 %Start Display Math Normal Tag VerbPlus Bracket
4 %%
5 <Normal>\' {yyleng--; yymore(); /* ignore apostrophes */}
6 <Normal>{L}+\\- {yyleng-=2; yymore(); /* ignore hyphens */}
7 <Normal>[a-zA-Z0-9_]+@[a-zA-Z0-9_.]+ ; /* ignore email addresses */
8 <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;
25 <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;
34 <Tag>[^}] ; /* ignore things up to next "}" */
35 <Tag>"}" BEGIN Normal;
36 <VerbPlus>[^+] ; /* ignore thing up to next "+" */
37 <VerbPlus>"+" BEGIN Normal;
38 <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>
52 int
53 main(int argc, char **argv)
54 {
55 int i;
57 if (argc==1) {
58 yyin = stdin;
59 BEGIN Normal; /* Starts yylex off in the right state */
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 BEGIN Normal; /* Starts yylex off in the right state */
69 yylex();
70 }
71 exit(0);
72 }
73 int
74 yywrap(void)
75 {
76 return 1;
77 }