1 package org.apache.maven.doxia.module.latex;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Writer;
23
24 import org.apache.maven.doxia.sink.Sink;
25 import org.apache.maven.doxia.sink.AbstractSinkTest;
26
27
28
29
30
31 public class LatexSinkTest
32 extends AbstractSinkTest
33 {
34
35 protected String outputExtension()
36 {
37 return "tex";
38 }
39
40
41 protected Sink createSink( Writer writer )
42 {
43 return new LatexSink( writer );
44 }
45
46
47 protected boolean isXmlSink()
48 {
49 return false;
50 }
51
52
53 protected String getTitleBlock( String title )
54 {
55 return "\\title{" + LatexSink.escaped( title ) + "}" + EOL;
56 }
57
58
59 protected String getAuthorBlock( String author )
60 {
61 return "\\author{" + LatexSink.escaped( author ) + "}" + EOL;
62 }
63
64
65 protected String getDateBlock( String date )
66 {
67 return "\\date{" + LatexSink.escaped( date ) + "}" + EOL;
68 }
69
70
71 protected String getHeadBlock()
72 {
73 return ( (LatexSink) getSink() ).defaultSinkCommands()
74 + "\\documentclass[a4paper]{article}" + EOL + EOL
75 + ( (LatexSink) getSink() ).defaultPreamble()
76 + "\\begin{document}" + EOL + EOL;
77 }
78
79
80 protected String getBodyBlock()
81 {
82 return "\\end{document}" + EOL;
83 }
84
85
86 protected String getSectionTitleBlock( String title )
87 {
88 return title;
89 }
90
91
92 protected String getSection1Block( String title )
93 {
94 return EOL + "\\section{" + title + "}" + EOL;
95 }
96
97
98 protected String getSection2Block( String title )
99 {
100 return EOL + "\\subsection{" + title + "}" + EOL;
101 }
102
103
104 protected String getSection3Block( String title )
105 {
106 return EOL + "\\subsubsection{" + title + "}" + EOL;
107 }
108
109
110 protected String getSection4Block( String title )
111 {
112 return EOL + "\\paragraph{" + title + "}" + EOL;
113 }
114
115
116 protected String getSection5Block( String title )
117 {
118 return EOL + "\\subparagraph{" + title + "}" + EOL;
119 }
120
121
122 protected String getListBlock( String item )
123 {
124 return EOL + "\\begin{itemize}" + EOL + "\\item " + LatexSink.escaped( item ) + EOL + "\\end{itemize}" + EOL;
125 }
126
127
128 protected String getNumberedListBlock( String item )
129 {
130 return EOL + "\\begin{enumerate}" + EOL + "\\renewcommand{\\theenumi}{\\roman{enumi}}" + EOL + "\\item "
131 + LatexSink.escaped( item ) + EOL + "\\end{enumerate}" + EOL;
132 }
133
134
135 protected String getDefinitionListBlock( String definum, String definition )
136 {
137 return EOL + "\\begin{description}" + EOL + "\\item[\\mbox{" + definum + "}] "
138 + definition + EOL + "\\end{description}" + EOL;
139 }
140
141
142 protected String getFigureBlock( String source, String caption )
143 {
144 String figureBlock = EOL + "\\begin{figure}[htb]" + EOL + "\\begin{center}" + EOL + "\\includegraphics{" + source + "}" + EOL
145 + "\\end{center}" + EOL;
146 if (caption != null )
147 {
148 figureBlock += "\\caption{Figure\\_caption}" + EOL;
149 }
150 figureBlock += "\\end{figure}" + EOL;
151 return figureBlock;
152 }
153
154
155 protected String getTableBlock( String cell, String caption )
156 {
157 return EOL + "\\begin{table}[htp]" + EOL + "\\begin{center}" + EOL + "\\begin{tabular}{c}" + EOL
158 + "\\begin{tabular}[t]{c}cell\\end{tabular}\\\\" + EOL + "\\end{tabular}" + EOL
159 + "\\end{center}" + EOL + "\\caption{Table\\_caption}" + EOL + "\\end{table}" + EOL;
160 }
161
162
163 protected String getParagraphBlock( String text )
164 {
165 return EOL + EOL + text + EOL;
166 }
167
168
169 protected String getVerbatimBlock( String text )
170 {
171 return EOL + "\\begin{small}" + EOL + "\\begin{Verbatim}[frame=single]" + EOL + text + EOL
172 + "\\end{Verbatim}" + EOL + "\\end{small}" + EOL;
173 }
174
175
176 protected String getHorizontalRuleBlock()
177 {
178 return EOL + "\\begin{center}\\rule[0.5ex]{\\linewidth}{1pt}\\end{center}" + EOL;
179 }
180
181
182 protected String getPageBreakBlock()
183 {
184 return EOL + "\\newpage" + EOL;
185 }
186
187
188 protected String getAnchorBlock( String anchor )
189 {
190 return "\\hypertarget{" + anchor + "}{" + anchor + "}";
191 }
192
193
194 protected String getLinkBlock( String link, String text )
195 {
196 return "\\hyperlink{" + link + "}{" + text + "}";
197 }
198
199
200 protected String getItalicBlock( String text )
201 {
202 return "\\textit{" + text + "}";
203 }
204
205
206 protected String getBoldBlock( String text )
207 {
208 return "\\textbf{" + text + "}";
209 }
210
211
212 protected String getMonospacedBlock( String text )
213 {
214 return "\\texttt{\\small " + text + "}";
215 }
216
217
218 protected String getLineBreakBlock()
219 {
220 return "\\newline" + EOL;
221 }
222
223
224 protected String getNonBreakingSpaceBlock()
225 {
226 return "~";
227 }
228
229
230 protected String getTextBlock( String text )
231 {
232
233 return "\\textasciitilde" + EOL + ",\\_=,\\_\\symbol{45},\\_+,\\_*,\\_[,\\_],"
234 + "\\_\\symbol{60},\\_\\symbol{62},\\_\\{,\\_\\},\\_\\textbackslash";
235 }
236
237
238 protected String getRawTextBlock( String text )
239 {
240 return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
241 }
242
243
244 protected String getCommentBlock( String text )
245 {
246 return EOL + "% Simple comment with ----";
247 }
248 }