7 void file_put(int fd
, char *s
)
11 size_t size
= strlen(s
);
12 while (size
> n
&& (c
= write(fd
, s
+ n
, size
- n
)) >= 0)
16 static void latex_doc_beg(int fd
)
18 file_put(fd
, "\\begin{document}\n");
21 static void latex_doc_end(int fd
)
23 file_put(fd
, "\\end{document}\n");
26 static void latex_head_beg(int fd
, int level
)
30 file_put(fd
, "\\section*{");
33 file_put(fd
, "\\subsection*{");
36 file_put(fd
, "\\subsection*{");
40 static void latex_head_end(int fd
)
45 static void latex_par_beg(int fd
)
49 static void latex_par_end(int fd
)
53 static void latex_put(int fd
, char *s
)
58 static void latex_list_beg(int fd
)
60 file_put(fd
, "\\begin{itemize}\n");
63 static void latex_list_end(int fd
)
65 file_put(fd
, "\\end{itemize}\n");
68 static void latex_item_beg(int fd
)
70 file_put(fd
, "\\item ");
73 static void latex_item_end(int fd
)
78 static void latex_pre_beg(int fd
)
80 file_put(fd
, "\\begin{verbatim}\n");
83 static void latex_pre_end(int fd
)
85 file_put(fd
, "\\end{verbatim}\n");
88 static void latex_formula_beg(int fd
)
93 static void latex_formula_end(int fd
)
95 file_put(fd
, " \\]\n");
98 static void latex_put_emph(int fd
, char *s
)
100 file_put(fd
, "\\emph{");
105 static void latex_put_raw(int fd
, char *s
)
110 static void latex_put_ref(int fd
, char *s
)
112 file_put(fd
, "\\cite{");
117 struct fmt_ops latex_ops
= {
118 .doc_beg
= latex_doc_beg
,
119 .doc_end
= latex_doc_end
,
120 .head_beg
= latex_head_beg
,
121 .head_end
= latex_head_end
,
122 .par_beg
= latex_par_beg
,
123 .par_end
= latex_par_end
,
124 .list_beg
= latex_list_beg
,
125 .list_end
= latex_list_end
,
126 .item_beg
= latex_item_beg
,
127 .item_end
= latex_item_end
,
128 .pre_beg
= latex_pre_beg
,
129 .pre_end
= latex_pre_end
,
130 .formula_beg
= latex_formula_beg
,
131 .formula_end
= latex_formula_end
,
132 .put_emph
= latex_put_emph
,
133 .put_raw
= latex_put_raw
,
134 .put_ref
= latex_put_ref
,
137 int main(int argc
, char **argv
)
139 struct txt
*txt
= txt_alloc(STDIN_FILENO
);
140 fmt(STDOUT_FILENO
, txt
, &latex_ops
);