1 # =======================================================================
2 # Created on: 2014-03-21
4 # Copyright (c) 1996-1999 Matra Datavision
5 # Copyright (c) 1999-2014 OPEN CASCADE SAS
7 # This file is part of Open CASCADE Technology software library.
9 # This library is free software; you can redistribute it and/or modify it under
10 # the terms of the GNU Lesser General Public License version 2.1 as published
11 # by the Free Software Foundation, with special exception defined in the file
12 # OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 # distribution for complete text of the license and disclaimer of any warranty.
15 # Alternatively, this file may be used under the terms of Open CASCADE
16 # commercial license or contractual agreement.
18 # Brief: This script contains auxilary functions which can be used
19 # in documentation generation process
20 # =======================================================================
22 # ==============================================
23 # Commonly used functions
24 # ==============================================
26 # Parses arguments line like "-arg1=val1 -arg2=val2 ..." to array args_names and map args_values
27 proc OCCDoc_ParseArguments {arguments} {
31 array set args_values {}
33 foreach arg $arguments {
34 if {[regexp {^(-)[a-z]+$} $arg] == 1} {
35 set name [string range $arg 1 [string length $arg]-1]
36 lappend args_names $name
37 set args_values($name) "NULL"
39 } elseif {[regexp {^(-)[a-z]+=.+$} $arg] == 1} {
40 set equal_symbol_position [string first "=" $arg]
41 set name [string range $arg 1 $equal_symbol_position-1]
42 lappend args_names $name
43 set value [string range $arg $equal_symbol_position+1 [string length $arguments]-1]
45 # To parse a list of values for -m parameter
46 if { [string first "," $value] != -1 } {
47 set value [split $value ","];
50 set args_values($name) $value
53 puts "Error in argument $arg."
60 # Returns script parent folder
61 proc OCCDoc_GetDoxDir {} {
62 return [file normalize [file dirname [info script]]/../dox]
65 # Returns OCCT root dir
66 proc OCCDoc_GetOCCTRootDir {} {
67 set path [OCCDoc_GetDoxDir]
68 return [file normalize $path/..]
72 proc OCCDoc_GetRootDir { {theProductsPath ""} } {
74 if { $theProductsPath == "" } {
75 return [OCCDoc_GetOCCTRootDir]
77 return [file normalize $theProductsPath]
81 # Returns OCCT include dir
82 proc OCCDoc_GetIncDir { {theProductsPath ""} } {
83 set path [OCCDoc_GetRootDir $theProductsPath]
87 # Returns OCCT source dir
88 proc OCCDoc_GetSourceDir { {theProductsPath ""} } {
89 set path [OCCDoc_GetRootDir $theProductsPath]
93 # Returns name of the package from the current toolkit
94 proc OCCDoc_GetNameFromPath { thePath } {
96 set splitted_path [split $thePath "/" ]
97 set package_name [lindex $splitted_path end]
102 # Returns the relative path between two folders
103 proc OCCDoc_GetRelPath {thePathFrom thePathTo} {
104 if { [file isdirectory "$thePathFrom"] == 0 } {
108 set aPathFrom [file normalize "$thePathFrom"]
109 set aPathTo [file normalize "$thePathTo"]
111 set aCutedPathFrom "${aPathFrom}/dummy"
112 set aRelatedDeepPath ""
114 while { "$aCutedPathFrom" != [file normalize "$aCutedPathFrom/.."] } {
115 set aCutedPathFrom [file normalize "$aCutedPathFrom/.."]
116 # does aPathTo contain aCutedPathFrom?
117 regsub -all $aCutedPathFrom $aPathTo "" aPathFromAfterCut
118 if { "$aPathFromAfterCut" != "$aPathTo" } { # if so
119 if { "$aCutedPathFrom" == "$aPathFrom" } { # just go higher, for example, ./somefolder/someotherfolder
120 set aPathTo ".${aPathTo}"
121 } elseif { "$aCutedPathFrom" == "$aPathTo" } { # remove the last "/"
122 set aRelatedDeepPath [string replace $aRelatedDeepPath end end ""]
124 regsub -all $aCutedPathFrom $aPathTo $aRelatedDeepPath aPathToAfterCut
125 regsub -all "//" $aPathToAfterCut "/" aPathToAfterCut
126 return $aPathToAfterCut
128 set aRelatedDeepPath "$aRelatedDeepPath../"
134 # Returns OCCT version string from file Standard_Version.hxx (if available)
135 proc OCCDoc_DetectCasVersion {} {
138 set filename "[OCCDoc_GetSourceDir]/Standard/Standard_Version.hxx"
139 if { [file exists $filename] } {
140 set fh [open $filename "r"]
141 set fh_loaded [read $fh]
143 regexp {[^/]\s*#\s*define\s+OCC_VERSION_COMPLETE\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver
144 regexp {[^/]\s*#\s*define\s+OCC_VERSION_DEVELOPMENT\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver_add
145 if { "$occt_ver_add" != "" } { set occt_ver ${occt_ver}.$occt_ver_add }
150 # Checks if the necessary tools exist
151 proc OCCDoc_DetectNecessarySoftware { DOXYGEN_PATH GRAPHVIZ_PATH INKSCAPE_PATH HHC_PATH PDFLATEX_PATH } {
153 upvar 1 DOXYGEN_PATH doxy_path
154 upvar 1 GRAPHVIZ_PATH graph_path
155 upvar 1 INKSCAPE_PATH inkscape_path
156 upvar 1 HHC_PATH hhc_path
157 upvar 1 PDFLATEX_PATH latex_path
166 if { "$::tcl_platform(platform)" == "windows" } {
169 if {"$is_win" == "yes"} {
182 set envPath $::env(PATH)
183 if { $is_win == "yes" } {
184 set searchPathsList [split $envPath ";"]
186 set searchPathsList [split $envPath ":"]
189 foreach path $searchPathsList {
190 if { ($is_win == "no") &&
191 (($path == "/usr/bin") || ($path == "/usr/local/bin")) } {
192 # Avoid searching in default bin location
195 if {$d_flag == "no"} {
196 if { [file exists $path/doxygen$exe] } {
197 catch { exec $path/doxygen -V } version_string
198 set version [lindex [split $version_string "\n"] 0]
199 puts "Info: $version "
200 puts " found in $path."
201 set doxy_path "$path/doxygen$exe"
205 if {$g_flag == "no"} {
206 if { [file exists $path/dot$exe] } {
207 catch { exec $path/dot -V } version
209 puts "Info: $version "
210 puts " found in $path."
211 set graph_path "$path/dot$exe"
215 if {$i_flag == "no"} {
216 if { [file exists $path/inkscape$exe] } {
217 catch { exec $path/inkscape -V } version
218 puts "Info: $version "
219 puts " found in $path."
220 set inkscape_path "$path/inkscape$exe"
224 if {$l_flag == "no"} {
225 if { [file exists $path/pdflatex$exe] } {
226 catch { exec $path/pdflatex -version } version
227 set version [lindex [split $version "\n"] 0]
228 puts "Info: $version "
229 puts " found in $path."
230 set latex_path "$path/pdflatex$exe"
234 if { ("$is_win" == "yes") && ($h_flag == "no") } {
235 if { [file exists $path/hhc.exe] } {
237 puts " found in $path."
238 set hhc_path "hhc$exe"
242 if { ($d_flag == "yes") &&
243 ($i_flag == "yes") &&
244 ($g_flag == "yes") &&
245 ($l_flag == "yes") &&
246 (($is_win == "yes") &&
247 ($h_flag == "yes")) } {
252 # On Windows search for hhc.exe in the default location
253 # if it has not been found yet
254 if { ("$is_win" == "yes") && ($h_flag == "no") } {
255 if { [info exists ::env(ProgramFiles\(x86\))] } {
257 set path "$::env(ProgramFiles\(x86\))\\HTML Help Workshop"
258 set hhc_path "$path\\hhc.exe"
260 puts " found in $path."
262 if { [info exists ::env(ProgramFiles)] } {
264 set path "$::env(ProgramFiles)\\HTML Help Workshop"
265 set hhc_path "$path\\hhc.exe"
267 puts " found in $path."
272 # On *nix-like platforms,
273 # check the default binary locations if the tools had not been found yet
274 if { $is_win == "no" &&
275 (($d_flag == "no") ||
278 ($l_flag == "no")) } {
280 set default_path { "/usr/bin" "/usr/local/bin" }
281 foreach path $default_path {
282 if {$d_flag == "no"} {
283 if { [file exists $path/doxygen$exe] } {
284 catch { exec $path/doxygen -V } version_string
285 set version [lindex [split $version_string "\n"] 0]
286 puts "Info: $version "
287 puts " found in $path."
288 set doxy_path "$path/doxygen$exe"
292 if {$g_flag == "no"} {
293 if { [file exists $path/dot$exe] } {
294 catch { exec $path/dot -V } version
296 puts "Info: $version "
297 puts " found in $path."
298 set graph_path "$path/dot$exe"
302 if {$i_flag == "no"} {
303 if { [file exists $path/inkscape$exe] } {
304 catch { exec $path/inkscape -V } version
305 puts "Info: $version "
306 puts " found in $path."
307 set inkscape_path "$path/inkscape$exe"
311 if {$l_flag == "no"} {
312 if { [file exists $path/pdflatex$exe] } {
313 catch { exec $path/pdflatex -version } version
314 set version [lindex [split $version "\n"] 0]
315 puts "Info: $version "
316 puts " found in $path."
317 set latex_path "$path/pdflatex$exe"
324 # Check if tools have been found
325 if { $d_flag == "no" } {
326 puts "Warning: Could not find doxygen installed."
329 if { $g_flag == "no" } {
330 puts "Warning: Could not find graphviz installed."
332 if { $i_flag == "no" } {
333 puts "Warning: Could not find inkscape installed."
335 if { $l_flag == "no" } {
336 puts "Warning: Could not find pdflatex installed."
338 if { ("$::tcl_platform(platform)" == "windows") && ($h_flag == "no") } {
339 puts "Warning: Could not find hhc installed."
345 # Convert SVG files to PDF format to allow including them to PDF
346 # (requires InkScape to be in PATH)
347 proc OCCDoc_ProcessSvg {latexDir verboseMode} {
349 foreach file [glob -nocomplain $latexDir/*.svg] {
350 if {$verboseMode == "YES"} {
351 puts "Info: Converting file $file..."
353 set pdffile "[file rootname $file].pdf"
354 if { [catch {exec inkscape -z -D --file=$file --export-pdf=$pdffile} res] } {
361 # ==============================================
362 # Reference Manual-specific functions
363 # ==============================================
365 # Finds dependencies between all modules
366 proc OCCDoc_CreateModulesDependencyGraph {dir filename modules mpageprefix} {
367 global module_dependency
369 if {![catch {open $dir/$filename.dot "w"} file]} {
370 puts $file "digraph $filename"
373 foreach mod $modules {
377 puts $file "\t$mod \[ URL = \"[string tolower $mpageprefix$mod.html]\" \]"
378 foreach mod_depend $module_dependency($mod) {
379 puts $file "\t$mod_depend -> $mod \[ dir = \"back\", color = \"midnightblue\", style = \"solid\" \]"
390 # Finds dependencies between all toolkits in module
391 proc OCCDoc_CreateModuleToolkitsDependencyGraph {dir filename modulename tpageprefix} {
392 global toolkits_in_module
393 global toolkit_dependency
394 global toolkit_parent_module
396 if {![catch {open $dir/$filename.dot "w"} file]} {
397 puts $file "digraph $filename"
400 foreach tk $toolkits_in_module($modulename) {
401 puts $file "\t$tk \[ URL = \"[string tolower $tpageprefix$tk.html]\"\ ]"
402 foreach tkd $toolkit_dependency($tk) {
403 if { [info exists toolkit_parent_module($tkd)] } {
404 if {$toolkit_parent_module($tkd) == $modulename} {
405 puts $file "\t$tkd -> $tk \[ dir = \"back\", color = \"midnightblue\", style = \"solid\" \]"
418 # Finds dependencies between the current toolkit and other toolkits
419 proc OCCDoc_CreateToolkitDependencyGraph {dir filename toolkitname tpageprefix} {
420 global toolkit_dependency
422 if {![catch {open $dir/$filename.dot "w"} file]} {
423 puts $file "digraph $filename"
426 puts $file "\t$toolkitname \[ URL = \"[string tolower $tpageprefix$toolkitname.html]\"\, shape = box ]"
427 foreach tkd $toolkit_dependency($toolkitname) {
428 puts $file "\t$tkd \[ URL = \"[string tolower $tpageprefix$tkd.html]\"\ , shape = box ]"
429 puts $file "\t$toolkitname -> $tkd \[ color = \"midnightblue\", style = \"solid\" \]"
432 if {[llength $toolkit_dependency($toolkitname)] > 1} {
433 puts $file "\taspect = 1"
443 # Fills arrays of modules, toolkits, dependency of modules/toolkits etc
444 proc OCCDoc_LoadData { {theProductsDir ""} } {
445 global toolkits_in_module
446 global toolkit_dependency
447 global toolkit_parent_module
448 global module_dependency
450 if { $theProductsDir == ""} {
451 set modules_files [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $theProductsDir]/OS/" *.tcl]
453 set modules_files [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $theProductsDir]/VAS/" *.tcl]
456 foreach module_file $modules_files {
460 set modules [OCCDoc_GetModulesList $theProductsDir]
461 foreach mod $modules {
466 # Get toolkits of current module
467 set toolkits_in_module($mod) [$mod:toolkits]
468 # Get all dependence of current toolkit
469 foreach tk $toolkits_in_module($mod) {
470 # set parent module of current toolkit
471 set toolkit_parent_module($tk) $mod
472 set exlibfile [open "[OCCDoc_GetSourceDir $theProductsDir]/$tk/EXTERNLIB" r]
473 set exlibfile_data [read $exlibfile]
474 set exlibfile_data [split $exlibfile_data "\n"]
476 set toolkit_dependency($tk) {}
477 foreach dtk $exlibfile_data {
478 if { ([string first "TK" $dtk 0] == 0) ||
479 ([string first "P" $dtk 0] == 0) } {
480 lappend toolkit_dependency($tk) $dtk
487 # Get modules dependency
488 foreach mod $modules {
489 set module_dependency($mod) {}
490 foreach tk $toolkits_in_module($mod) {
491 foreach tkd $toolkit_dependency($tk) {
492 if { [info exists toolkit_parent_module($tkd)] } {
493 if { $toolkit_parent_module($tkd) != $mod &&
494 [lsearch $module_dependency($mod) $toolkit_parent_module($tkd)] == -1} {
495 lappend module_dependency($mod) $toolkit_parent_module($tkd)
503 # Returns list of packages of the given toolkit
504 proc OCCDoc_GetPackagesList { theToolKitPath } {
508 # Open file with list of packages of the given toolkit
509 set fileid [open "$theToolKitPath/PACKAGES" "r"]
511 while { [eof $fileid] == 0 } {
512 set str [gets $fileid]
514 lappend packages_list $str
520 return $packages_list
523 # Returns list of modules from UDLIST
524 proc OCCDoc_GetModulesList { {theProductsDir ""} } {
526 if { $theProductsDir == "" } {
527 source "[OCCDoc_GetSourceDir $theProductsDir]/OS/Modules.tcl"
528 # load a command from this file
529 set modules [OS:Modules]
531 source "[OCCDoc_GetSourceDir $theProductsDir]/VAS/Products.tcl"
532 # load a command from this file
533 set modules [VAS:Products]
534 set modules [lsearch -not -all -inline $modules "VAS"]
540 # Returns list of desired files in the specified location
541 proc OCCDoc_GetHeadersList { theDesiredContent thePackageName {theProductsDir ""} } {
543 # Get list of header files with path
544 set files_list [split [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $theProductsDir]/$thePackageName" "${thePackageName}.hxx" "${thePackageName}_*.hxx"]]
546 # Get content according to desired type ('p' for path and 'f' for filenames only)
547 if { $theDesiredContent == "p" } {
549 } elseif { $theDesiredContent == "f" } {
551 # Cut paths from filenames
552 foreach file $files_list {
553 set elem_index [lsearch $files_list $file]
554 lset files_list $elem_index [OCCDoc_GetNameFromPath [lindex $files_list $elem_index]]
560 # Returns location of the toolkit
561 proc OCCDoc_Locate { theToolKitName {theProductsDir ""} } {
562 set tk_dir "[OCCDoc_GetSourceDir $theProductsDir]/[OCCDoc_GetNameFromPath $theToolKitName]"
566 # Gets contents of the given html node (for Post-processing)
567 proc OCCDoc_GetNodeContents {node props html} {
568 set openTag "<$node$props>"
569 set closingTag "</$node>"
570 set start [string first $openTag $html]
574 set start [expr $start + [string length $openTag]]
575 set end [string length $html]
576 set html [string range $html $start $end]
577 set start [string first $closingTag $html]
578 set end [string length $html]
582 set start [expr $start - 1]
583 return [string range $html 0 $start]
586 # Generates main page file describing module structure
587 proc OCCDoc_MakeMainPage {outDir outFile modules {theProductsDir ""} } {
590 set one_module [expr [llength $modules] == 1]
591 set fd [open $outFile "w"]
593 set module_prefix "module_"
594 set toolkit_prefix "toolkit_"
595 set package_prefix "package_"
597 if { ! [file exists "$outDir/html"] } {
598 file mkdir "$outDir/html"
601 OCCDoc_LoadData $theProductsDir
603 # Main page: list of modules
604 if { ! $one_module } {
606 puts $fd "\\mainpage Open CASCADE Technology"
608 foreach mod $modules {
609 puts $fd "\\li \\subpage [string tolower $module_prefix$mod]"
611 # insert modules relationship diagramm
612 puts $fd "\\dotfile [OCCDoc_CreateModulesDependencyGraph $outDir/html schema_all_modules $modules $module_prefix]"
616 # One page per module: list of toolkits
618 foreach mod $modules {
624 puts $fd "\\mainpage OCCT Module [$mod:name]"
626 puts $fd "\\page [string tolower module_$mod] Module [$mod:name]"
628 foreach tk [lsort [$mod:toolkits]] {
630 puts $fd "\\li \\subpage [string tolower $toolkit_prefix$tk]"
632 puts $fd "\\dotfile [OCCDoc_CreateModuleToolkitsDependencyGraph $outDir/html schema_$mod $mod $toolkit_prefix]"
636 # One page per toolkit: list of packages
638 foreach tk $toolkits {
640 puts $fd "\\page [string tolower toolkit_$tk] Toolkit $tk"
641 foreach pk [lsort [OCCDoc_GetPackagesList [OCCDoc_Locate $tk $theProductsDir]]] {
643 set u [OCCDoc_GetNameFromPath $pk]
644 puts $fd "\\li \\subpage [string tolower $package_prefix$u]"
646 puts $fd "\\dotfile [OCCDoc_CreateToolkitDependencyGraph $outDir/html schema_$tk $tk $toolkit_prefix]"
650 # One page per package: list of classes
651 foreach pk $packages {
652 set u [OCCDoc_GetNameFromPath $pk]
654 puts $fd "\\page [string tolower $package_prefix$u] Package $u"
655 foreach hdr [lsort [OCCDoc_GetHeadersList "f" "$pk" "$theProductsDir"]] {
656 if { ! [regexp {^Handle_} $hdr] && [regexp {(.*)[.]hxx} $hdr str obj] } {
657 puts $fd "\\li \\subpage $obj"
668 # Parses generated files to add a navigation path
669 proc OCCDoc_PostProcessor {outDir} {
670 puts "[clock format [clock seconds] -format {%Y.%m.%d %H:%M}] Post-process is started ..."
671 append outDir "/html"
672 set files [glob -nocomplain -type f $outDir/package_*]
673 if { $files != {} } {
674 foreach f [lsort $files] {
675 set packageFilePnt [open $f r]
676 set packageFile [read $packageFilePnt]
677 set navPath [OCCDoc_GetNodeContents "div" " id=\"nav-path\" class=\"navpath\"" $packageFile]
678 set packageName [OCCDoc_GetNodeContents "div" " class=\"title\"" $packageFile]
679 regsub -all {<[^<>]*>} $packageName "" packageName
681 # add package link to nav path
682 set first [expr 1 + [string last "/" $f]]
683 set last [expr [string length $f] - 1]
684 set packageFileName [string range $f $first $last]
685 set end [string first "</ul>" $navPath]
686 set end [expr $end - 1]
687 set navPath [string range $navPath 0 $end]
688 append navPath " <li class=\"navelem\"><a class=\"el\" href=\"$packageFileName\">$packageName</a> </li>\n </ul>"
690 # get list of files to update
691 set listContents [OCCDoc_GetNodeContents "div" " class=\"textblock\"" $packageFile]
692 set listContents [OCCDoc_GetNodeContents "ul" "" $listContents]
693 set lines [split $listContents "\n"]
694 foreach line $lines {
695 if {[regexp {href=\"([^\"]*)\"} $line tmpLine classFileName]} {
696 # check if anchor is there
697 set anchorPos [string first "#" $classFileName]
698 if {$anchorPos != -1} {
699 set classFileName [string range $classFileName 0 [expr $anchorPos - 1]]
703 set classFilePnt [open $outDir/$classFileName r+]
704 set classFile [read $classFilePnt]
706 # find position of content block
707 set contentPos [string first "<div class=\"header\">" $classFile]
708 set navPart [string range $classFile 0 [expr $contentPos - 1]]
710 # position where to insert nav path
711 set posToInsert [string last "</div>" $navPart]
712 set prePart [string range $classFile 0 [expr $posToInsert - 1]]
713 set postPart [string range $classFile $posToInsert [string length $classFile]]
715 append newClassFile $prePart " <div id=\"nav-path\" class=\"navpath\">" $navPath \n " </div>" \n $postPart
717 # write updated content
719 puts $classFilePnt $newClassFile
723 close $packageFilePnt
727 puts "no files found"
732 # ======================================
733 # User Guides-specific functions
734 # ======================================
736 # Loads a list of docfiles from file FILES.txt
737 proc OCCDoc_LoadFilesList {} {
739 set INPUTDIR [OCCDoc_GetDoxDir]
741 global available_docfiles
742 set available_docfiles {}
744 # Read data from file
745 if { [file exists "$INPUTDIR/FILES_HTML.txt"] == 1 } {
746 set FILE [open "$INPUTDIR/FILES_HTML.txt" r]
748 set line [string trim [gets $FILE]]
750 # trim possible comments starting with '#'
751 set line [regsub {\#.*} $line {}]
753 lappend available_docfiles $line
767 # Read data from file
768 if { [file exists "$INPUTDIR/FILES_PDF.txt"] } {
769 set FILE [open "$INPUTDIR/FILES_PDF.txt" r]
771 set line [string trim [gets $FILE]]
773 # Trim possible comments starting with '#'
774 set line [regsub {\#.*} $line {}]
776 lappend available_pdf $line
789 # Writes new TeX file for conversion from tex to pdf for a specific doc
790 proc OCCDoc_MakeRefmanTex {fileName latexDir verboseMode latexFilesList} {
792 if { $verboseMode == "YES" } {
793 puts "Info: Making refman.tex file for $fileName..."
795 set DOCNAME "$latexDir/refman.tex"
796 if {[file exists $DOCNAME] == 1} {
797 file delete -force $DOCNAME
800 # Copy template file to latex folder
801 file copy "[OCCDoc_GetDoxDir]/resources/occt_pdf_template.tex" $DOCNAME
803 # Get templatized data
804 set texfile [open $DOCNAME "r"]
805 set texfile_loaded [read $texfile]
808 # Replace dummy values
809 set year [clock format [clock seconds] -format {%Y}]
810 set texfile [open $DOCNAME "w"]
811 set casVersion [OCCDoc_DetectCasVersion]
813 # Get name of the document
815 foreach aFileName $latexFilesList {
816 # Find the file in FILES_PDF.txt
817 set parsedFileName [split $aFileName "/" ]
818 set newfileName [string range $fileName [expr [string first "__" $fileName] + 2] end]
820 if { [lsearch -nocase $parsedFileName "$newfileName.md" ] != -1 } {
821 set filepath "[OCCDoc_GetDoxDir]/$aFileName"
822 if { [file exists $filepath] } {
823 set MDFile [open $filepath "r"]
824 set label [split [gets $MDFile] "\{"]
825 set docLabel [lindex $label 0]
833 set texfile_loaded [string map [list DEFDOCLABEL "$docLabel" DEFCASVERSION "$casVersion" DEFFILENAME "$fileName" DEFYEAR "$year"] $texfile_loaded]
836 puts $texfile $texfile_loaded
841 # Postprocesses generated TeX files
842 proc OCCDoc_ProcessTex {{texFiles {}} {latexDir} verboseMode} {
844 foreach TEX $texFiles {
845 if {$verboseMode == "YES"} {
846 puts "Info: Preprocessing file $TEX..."
849 if {![file exists $TEX]} {
850 puts "Error: file $TEX does not exist."
854 set IN_F [open "$TEX" "r"]
855 set TMPFILENAME "$latexDir/temp.tex"
856 set OUT_F [open $TMPFILENAME w]
859 set line [gets $IN_F]
860 if { [string first "\\includegraphics" $line] != -1 } {
861 # replace svg extension by pdf
862 set line [regsub {[.]svg} $line ".pdf"]
863 # Center images in TeX files
864 set line "\\begin{center}\n $line\n\\end{center}"
865 } elseif { [string first "\\subsection" $line] != -1 } {
866 # Replace \subsection with \section tag
867 regsub -all "\\\\subsection" $line "\\\\section" line
868 } elseif { [string first "\\subsubsection" $line] != -1 } {
869 # Replace \subsubsection with \subsection tag
870 regsub -all "\\\\subsubsection" $line "\\\\subsection" line
871 } elseif { [string first "\\paragraph" $line] != -1 } {
872 # Replace \paragraph with \subsubsection tag
873 regsub -all "\\\\paragraph" $line "\\\\subsubsection" line
884 file delete -force $TEX
885 file rename $TMPFILENAME $TEX