2 Copyright (C) 1994-2007 Frans Slothouber, Jacco van Weert, Petteri Kettunen,
3 Bernd Koesling, Thomas Aglassinger, Anthon Pang, Stefan Kost, David Druffner,
4 Sasha Vasko, Kai Hofmann, Thierry Pierron, Friedrich Haase, and Gergely Budai.
6 This file is part of ROBODoc
8 ROBODoc is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /****h* ROBODoc/LaTeX_Generator
25 * Generator for LaTeX output. Supports singledoc mode.
28 * TODO More documentation.
36 #include "generator.h"
39 #include "latex_generator.h"
47 static int verbatim = FALSE;
50 /****f* LaTeX_Generator/RB_LaTeX_Generate_String
52 * Write a string to the destination document, escaping
53 * characters where necessary.
57 void RB_LaTeX_Generate_String(
62 int l = strlen( a_string );
65 for ( i = 0; i < l; i++ )
68 RB_LaTeX_Generate_Char( dest_doc, c );
73 void RB_LaTeX_Generate_False_Link(
77 RB_LaTeX_Generate_String( dest_doc, name );
80 void RB_LaTeX_Generate_Item_Begin(
87 void RB_LaTeX_Generate_Item_End(
95 /* RB_LaTeX_Generate_Item_Name( FILE* dest_doc, char *name ) */
97 /* RB_LaTeX_Generate_String( dest_doc, name ); */
98 /* fprintf( dest_doc, "\n" ); */
102 /* Lowtexx 21.09.2005 11:02 */
103 /* I think it looks better like this. This wastes less space in pdf-document. */
104 void RB_LaTeX_Generate_Item_Name(
108 fprintf( dest_doc, "\\textbf{" );
109 RB_LaTeX_Generate_String( dest_doc, name );
111 // In alternate format, item names stand alone (Thuffir)
112 if ( course_of_action.do_altlatex )
113 fprintf( dest_doc, "}\n" );
115 fprintf( dest_doc, ":}\\hspace{0.08in}" );
119 void RB_LaTeX_Generate_BeginSection(
123 struct RB_header *header )
127 // Generate a new page for every section in alternate format
128 if ( course_of_action.do_altlatex )
129 fprintf( dest_doc, "\\newpage\n" );
131 // If \part enabled, we have a level deeper
132 // So enable the level '0'
133 if ( course_of_action.do_latexparts )
139 fprintf( dest_doc, "\\part{" );
142 fprintf( dest_doc, "\\section{" );
145 fprintf( dest_doc, "\\subsection{" );
148 fprintf( dest_doc, "\\subsubsection{" );
151 /* Too deep so just make it a subsubsection */
152 fprintf( dest_doc, "\\subsubsection{" );
155 // Print Header "First" name
156 RB_LaTeX_Generate_String( dest_doc, name );
158 for ( i = 1; i < header->no_names; i++ )
160 RB_LaTeX_Generate_String( dest_doc, ", " );
161 RB_LaTeX_Generate_String( dest_doc, header->names[i] );
163 fprintf( dest_doc, "}\n" );
165 // Print Parent if any
166 if ( header->parent )
168 fprintf( dest_doc, "\\textsl{[ " );
169 RB_LaTeX_Generate_String( dest_doc, header->parent->function_name );
170 fprintf( dest_doc, " ]}\n" );
174 fprintf( dest_doc, "\\textsl{[ " );
175 RB_LaTeX_Generate_String( dest_doc, header->htype->indexName );
176 fprintf( dest_doc, " ]}\n\n" );
179 void RB_LaTeX_Generate_EndSection(
190 char *RB_LaTeX_Get_Default_Extension(
197 /****f* LaTeX_Generator/RB_LaTeX_Generate_Doc_Start
199 * RB_LaTeX_Generate_Doc_Start --
203 void RB_LaTeX_Generate_Doc_Start(
209 fprintf( dest_doc, "%% Document: %s\n", name );
210 fprintf( dest_doc, "%% Source: %s\n", src_name );
212 if ( course_of_action.do_nogenwith )
218 fprintf( dest_doc, "%% " COMMENT_ROBODOC );
219 /* Documentation is the users not ours fprintf( dest_doc, "%% " COMMENT_COPYRIGHT ); */
222 if ( course_of_action.do_headless )
224 /* The user wants a headless document, so we skip all
225 * initialization. It is up to the user to put this in.
230 fprintf( dest_doc, "\\documentclass{article}\n" );
231 fprintf( dest_doc, "\\usepackage{makeidx}\n" );
232 fprintf( dest_doc, "\\usepackage{graphicx}\n" );
234 // Check if we have to use the inputenc package
237 fprintf( dest_doc, "\\usepackage[%s]{inputenc}\n", charset );
240 // Alternate mode, works better with pdflatex and DIN A4 sheets
241 // At least for me :) (Thuffir)
242 if ( course_of_action.do_altlatex )
244 fprintf( dest_doc, "\\oddsidemargin 0 cm\n" );
245 fprintf( dest_doc, "\\evensidemargin 0 cm\n" );
246 fprintf( dest_doc, "\\topmargin 0 cm\n" );
247 fprintf( dest_doc, "\\textwidth 16 cm\n" );
248 fprintf( dest_doc, "\\textheight 22 cm\n" );
252 /* I guess this is unecessarry (same definitions twice ?)
253 fprintf( dest_doc, "\\oddsidemargin 0.15 in\n" );
254 fprintf( dest_doc, "\\evensidemargin 0.35 in\n" );
255 fprintf( dest_doc, "\\marginparwidth 1 in \n" );
258 fprintf( dest_doc, "\\oddsidemargin 0.25 in \n" );
259 fprintf( dest_doc, "\\evensidemargin 0.25 in\n" );
260 fprintf( dest_doc, "\\marginparwidth 0.75 in\n" );
261 fprintf( dest_doc, "\\textwidth 5.875 in\n" );
265 fprintf( dest_doc, "\\setlength{\\parindent}{0in}\n" );
266 fprintf( dest_doc, "\\setlength{\\parskip}{.08in}\n\n" );
268 /* changed default header to use boldface (vs slant) */
269 fprintf( dest_doc, "\\pagestyle{headings}\n" );
271 // Set document title
272 fprintf( dest_doc, "\\title{%s}\n",
273 document_title ? document_title : DEFAULT_DOCTITILE );
275 if ( course_of_action.do_nogenwith )
277 fprintf( dest_doc, "\\author{Documentation Generator}\n" );
281 fprintf( dest_doc, "\\author{%s}\n", COMMENT_ROBODOC );
284 fprintf( dest_doc, "\\makeindex\n" );
285 fprintf( dest_doc, "\\begin{document}\n" );
286 fprintf( dest_doc, "\\maketitle\n" );
288 // In alternate mode, we generate INDEX at the end of document
289 if ( course_of_action.do_altlatex )
291 fprintf( dest_doc, "\\newpage\n" );
295 fprintf( dest_doc, "\\printindex\n" );
298 /* autogenerate table of contents! */
299 fprintf( dest_doc, "\\tableofcontents\n" );
301 // We don't need this in alternate format, since every section begins
302 // with a \newpage (Thuffir)
303 if ( !( course_of_action.do_altlatex ) )
304 fprintf( dest_doc, "\\newpage\n" );
306 /* trick to disable the autogenerated \newpage */
307 fprintf( dest_doc, "\n" );
311 /****f* LaTeX_Generator/RB_LaTeX_Generate_Doc_End
313 * RB_LaTeX_Generate_Doc_End --
317 void RB_LaTeX_Generate_Doc_End(
323 // In alternate mode, we generate INDEX at the end of document
324 if ( course_of_action.do_altlatex )
326 fprintf( dest_doc, "\\printindex\n" );
329 if ( course_of_action.do_footless )
331 /* The user does not want the foot of the
337 fprintf( dest_doc, "\\end{document}\n" );
342 /****f* LaTeX_Generator/RB_LaTeX_Generate_Index_Entry
344 * Creates a entry for the index.
349 void RB_LaTeX_Generate_Index_Entry(
351 struct RB_header *cur_header )
353 assert( cur_header->function_name );
355 fprintf( dest_doc, "\\index{unsorted!" );
356 RB_LaTeX_Generate_String( dest_doc, cur_header->function_name );
357 if ( cur_header->is_internal )
359 fprintf( dest_doc, "}\\index{internal\\_%s!",
360 cur_header->htype->indexName );
364 fprintf( dest_doc, "}\\index{%s!", cur_header->htype->indexName );
366 RB_LaTeX_Generate_String( dest_doc, cur_header->function_name );
367 fprintf( dest_doc, "}\n" );
370 /****f* LaTeX_Generator/RB_LaTeX_Generate_Header_Start
372 * RB_LaTeX_Generate_Header_Start --
376 void RB_LaTeX_Generate_Header_Start(
378 struct RB_header *cur_header )
380 fprintf( dest_doc, "\\subsection{" );
381 RB_LaTeX_Generate_String( dest_doc, cur_header->name );
382 fprintf( dest_doc, "}\n" );
386 /****f* LaTeX_Generator/RB_LaTeX_Generate_Header_End
388 * RB_LaTeX_Generate_Header_End --
392 void RB_LaTeX_Generate_Header_End(
394 struct RB_header *cur_header )
397 fputc( '\n', dest_doc );
401 /*x**f* LaTeX_Generator/RB_LaTeX_Generate_Index
403 * RB_LaTeX_Generate_Index --
407 void RB_LaTeX_Generate_Index(
416 RB_Generate_Doc_Start( dest, source, "Master File", 0 );
417 RB_Generate_LaTeX_Includes( dest );
418 RB_Generate_Doc_End( dest, source );
423 /****f* LaTeX_Generator/RB_LaTeX_Generate_Index_Table
425 * RB_LaTeX_Generate_Index_Table --
429 void RB_LaTeX_Generate_Index_Table(
441 /****f* LaTeX_Generator/Generate_LaTeX_Includes
443 * Generate_LaTeX_Includes -- generate include commands
445 * void RB_Generate_LaTeX_Includes (FILE *dest)
447 * Generates a series of \include commands to include the
448 * documentation generated for each source file into one
453 void RB_Generate_LaTeX_Includes(
459 struct RB_link *cur_link;
461 for ( cur_link = first_link; cur_link; cur_link = cur_link->next_link )
464 if ( cur_link->type == NO_HEADER )
465 fprintf( dest, "\\include{%s}\n", cur_link->label_name );
473 /****f* LaTeX_Generator/RB_LaTeX_Generate_Empty_Item
475 * RB_LaTeX_Generate_Empty_Item --
479 void RB_LaTeX_Generate_Empty_Item(
482 fprintf( dest_doc, "\\\\\n" );
486 /****f* LaTeX_Generator/RB_LaTeX_Generate_EscapedChar
488 * Generate a single character. These characters are outside
489 * a begin{verbatim} end{verbatim} block. So we need to escape is
490 * special characters.
499 * void RB_LaTeX_Generate_EscapedChar( FILE* dest_doc, int c )
501 * RB_LaTeX_Generate_Char()
505 void RB_LaTeX_Generate_EscapedChar(
520 fputc( '\\', dest_doc );
521 fputc( c, dest_doc );
523 /* lowtexx 21.09.2005 11:12 */
524 /* Replace these characters by the correct latex-code */
526 fprintf( dest_doc, "$\\backslash$" );
529 fprintf( dest_doc, "\\textless " );
532 fprintf( dest_doc, "\\textgreater " );
536 fputc( c, dest_doc );
542 /****f* LaTeX_Generator/RB_LaTeX_Generate_Char
544 * Generate a single character. These characters are generated
545 * within a begin{verbatim} end{verbatim} block So no escaping is
548 * void RB_LaTeX_Generate_Char( FILE* dest_doc, int c )
552 void RB_LaTeX_Generate_Char(
567 fputc( c, dest_doc );
572 RB_LaTeX_Generate_EscapedChar( dest_doc, c );
577 void LaTeX_Generate_Begin_Paragraph(
580 fprintf( dest_doc, "\n" );
583 void LaTeX_Generate_End_Paragraph(
586 fprintf( dest_doc, "\n" );
590 void LaTeX_Generate_Begin_Preformatted(
593 fprintf( dest_doc, "\\begin{verbatim}\n" );
597 void LaTeX_Generate_End_Preformatted(
601 fprintf( dest_doc, "\\end{verbatim}\n" );
605 void LaTeX_Generate_Begin_List(
608 fprintf( dest_doc, "\\begin{itemize}\n" );
611 void LaTeX_Generate_End_List(
614 fprintf( dest_doc, "\\end{itemize}\n" );
617 void LaTeX_Generate_Begin_List_Item(
620 fprintf( dest_doc, " \\item " );
623 void LaTeX_Generate_End_List_Item(
627 // fprintf( dest_doc, "" );
632 /* lowtexx 21.09.2005 11:23 */
633 /* added some functions to create links in latex documents */
635 /****f* LaTeX_Generator/RB_LaTeX_Generate_Label
637 * RB_LaTeX_Generate_Label --
639 * void RB_LaTeX_Generate_Label( FILE* dest_doc, char* name)
641 * dest_doc -- the file to which the text is written
642 * name -- the unique name of the label to create
646 void RB_LaTeX_Generate_Label(
651 int l = strlen( name );
654 fprintf( dest_doc, "\\label{ch:" );
655 for ( i = 0; i < l; ++i )
658 if ( utf8_isalnum( c ) )
660 RB_LaTeX_Generate_Char( dest_doc, c );
665 // replaced by underscore
666 fputc( '_', dest_doc );
669 fprintf( dest_doc, "}\n" );
675 /****f* LaTeX_Generator/RB_LaTeX_Generate_Link
677 * RB_LaTeX_Generate_Link --
679 * void RB_LaTeX_Generate_Link( FILE *cur_doc, char *cur_name,
680 * char *filename, char *labelname,
683 * cur_doc -- the file to which the text is written
684 * cur_name -- the name of the destination file (unused)
685 * (the file from which we link)
686 * filename -- the name of the file that contains the link
687 * (the file we link to) (unused)
688 * labelname-- the name of the unique label of the link.
689 * linkname -- the name of the link as shown to the user (unused).
693 void RB_LaTeX_Generate_Link(
704 // Only generate links outside the verbatim sections
705 // LaTeX does not seem to recognise them inside (Thuffir)
706 if ( verbatim == FALSE )
707 fprintf( cur_doc, " (\\ref{ch:%s})", labelname );