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 # =======================================================================
19 # This script contains auxilary functions which can be used
20 # in documentation generation process
21 # =======================================================================
23 # ==============================================
24 # Commonly used functions
25 # ==============================================
27 # Parses arguments line like "-arg1=val1 -arg2=val2 ..." to array args_names and map args_values
28 proc OCCDoc_ParseArguments {arguments} {
32 array set args_values {}
34 foreach arg $arguments {
35 if {[regexp {^(-)[a-z]+$} $arg] == 1} {
36 set name [string range $arg 1 [string length $arg]-1]
37 lappend args_names $name
38 set args_values($name) "NULL"
40 } elseif {[regexp {^(-)[a-z]+=.+$} $arg] == 1} {
41 set equal_symbol_position [string first "=" $arg]
42 set name [string range $arg 1 $equal_symbol_position-1]
43 lappend args_names $name
44 set value [string range $arg $equal_symbol_position+1 [string length $arguments]-1]
46 # To parse a list of values for -m parameter
47 if { [string first "," $value] != -1 } {
48 set value [split $value ","];
51 set args_values($name) $value
54 puts "Error in argument $arg."
61 # Returns script parent folder
62 proc OCCDoc_GetDoxDir {} {
63 return [file normalize [file dirname [info script]]/../dox]
66 # Returns OCCT root dir
67 proc OCCDoc_GetOCCTRootDir {} {
68 set path [OCCDoc_GetDoxDir]
69 return [file normalize $path/..]
73 proc OCCDoc_GetRootDir { {theProductsPath ""} } {
75 if { $theProductsPath == "" } {
76 return [OCCDoc_GetOCCTRootDir]
78 return [file normalize $theProductsPath]
82 # Returns OCCT include dir
83 proc OCCDoc_GetIncDir { {theProductsPath ""} } {
84 set path [OCCDoc_GetRootDir $theProductsPath]
88 # Returns OCCT source dir
89 proc OCCDoc_GetSourceDir { {theProductsPath ""} } {
90 set path [OCCDoc_GetRootDir $theProductsPath]
94 # Returns name of the package from the current toolkit
95 proc OCCDoc_GetNameFromPath { thePath } {
97 set splitted_path [split $thePath "/" ]
98 set package_name [lindex $splitted_path end]
103 # Returns the relative path between two folders
104 proc OCCDoc_GetRelPath {thePathFrom thePathTo} {
105 if { [file isdirectory "$thePathFrom"] == 0 } {
109 set aPathFrom [file normalize "$thePathFrom"]
110 set aPathTo [file normalize "$thePathTo"]
112 set aCutedPathFrom "${aPathFrom}/dummy"
113 set aRelatedDeepPath ""
115 while { "$aCutedPathFrom" != [file normalize "$aCutedPathFrom/.."] } {
116 set aCutedPathFrom [file normalize "$aCutedPathFrom/.."]
117 # does aPathTo contain aCutedPathFrom?
118 regsub -all $aCutedPathFrom $aPathTo "" aPathFromAfterCut
119 if { "$aPathFromAfterCut" != "$aPathTo" } { # if so
120 if { "$aCutedPathFrom" == "$aPathFrom" } { # just go higher, for example, ./somefolder/someotherfolder
121 set aPathTo ".${aPathTo}"
122 } elseif { "$aCutedPathFrom" == "$aPathTo" } { # remove the last "/"
123 set aRelatedDeepPath [string replace $aRelatedDeepPath end end ""]
125 regsub -all $aCutedPathFrom $aPathTo $aRelatedDeepPath aPathToAfterCut
126 regsub -all "//" $aPathToAfterCut "/" aPathToAfterCut
127 return $aPathToAfterCut
129 set aRelatedDeepPath "$aRelatedDeepPath../"
135 # Returns OCCT version string from file Standard_Version.hxx (if available)
136 proc OCCDoc_DetectCasVersion {} {
139 set filename "[OCCDoc_GetSourceDir]/Standard/Standard_Version.hxx"
140 if { [file exists $filename] } {
141 set fh [open $filename "r"]
142 set fh_loaded [read $fh]
144 regexp {[^/]\s*#\s*define\s+OCC_VERSION_COMPLETE\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver
145 regexp {[^/]\s*#\s*define\s+OCC_VERSION_DEVELOPMENT\s+\"([^\s]*)\"} $fh_loaded dummy occt_ver_add
146 if { "$occt_ver_add" != "" } { set occt_ver ${occt_ver}.$occt_ver_add }
151 # Checks if the necessary tools exist
152 proc OCCDoc_DetectNecessarySoftware { DOXYGEN_PATH GRAPHVIZ_PATH INKSCAPE_PATH HHC_PATH PDFLATEX_PATH } {
154 upvar 1 DOXYGEN_PATH doxy_path
155 upvar 1 GRAPHVIZ_PATH graph_path
156 upvar 1 INKSCAPE_PATH inkscape_path
157 upvar 1 HHC_PATH hhc_path
158 upvar 1 PDFLATEX_PATH latex_path
167 if { "$::tcl_platform(platform)" == "windows" } {
170 if {"$is_win" == "yes"} {
183 set envPath $::env(PATH)
184 if { $is_win == "yes" } {
185 set searchPathsList [split $envPath ";"]
187 set searchPathsList [split $envPath ":"]
190 foreach path $searchPathsList {
191 if { ($is_win == "no") &&
192 (($path == "/usr/bin") || ($path == "/usr/local/bin")) } {
193 # Avoid searching in default bin location
196 if {$d_flag == "no"} {
197 if { [file exists $path/doxygen$exe] } {
198 catch { exec $path/doxygen -V } version_string
199 set version [lindex [split $version_string "\n"] 0]
200 puts "Info: $version "
201 puts " found in $path."
202 set doxy_path "$path/doxygen$exe"
206 if {$g_flag == "no"} {
207 if { [file exists $path/dot$exe] } {
208 catch { exec $path/dot -V } version
210 puts "Info: $version "
211 puts " found in $path."
212 set graph_path "$path/dot$exe"
216 if {$i_flag == "no"} {
217 if { [file exists $path/inkscape$exe] } {
218 catch { exec $path/inkscape -V } version
219 puts "Info: $version "
220 puts " found in $path."
221 set inkscape_path "$path/inkscape$exe"
225 if {$l_flag == "no"} {
226 if { [file exists $path/pdflatex$exe] } {
227 catch { exec $path/pdflatex -version } version
228 set version [lindex [split $version "\n"] 0]
229 puts "Info: $version "
230 puts " found in $path."
231 set latex_path "$path/pdflatex$exe"
235 if { ("$is_win" == "yes") && ($h_flag == "no") } {
236 if { [file exists $path/hhc.exe] } {
238 puts " found in $path."
239 set hhc_path "hhc$exe"
243 if { ($d_flag == "yes") &&
244 ($i_flag == "yes") &&
245 ($g_flag == "yes") &&
246 ($l_flag == "yes") &&
247 (($is_win == "yes") &&
248 ($h_flag == "yes")) } {
253 # On Windows search for hhc.exe in the default location
254 # if it has not been found yet
255 if { ("$is_win" == "yes") && ($h_flag == "no") } {
256 if { [info exists ::env(ProgramFiles\(x86\))] } {
258 set path "$::env(ProgramFiles\(x86\))\\HTML Help Workshop"
259 set hhc_path "$path\\hhc.exe"
261 puts " found in $path."
263 if { [info exists ::env(ProgramFiles)] } {
265 set path "$::env(ProgramFiles)\\HTML Help Workshop"
266 set hhc_path "$path\\hhc.exe"
268 puts " found in $path."
273 # On *nix-like platforms,
274 # check the default binary locations if the tools had not been found yet
275 if { $is_win == "no" &&
276 (($d_flag == "no") ||
279 ($l_flag == "no")) } {
281 set default_path { "/usr/bin" "/usr/local/bin" }
282 foreach path $default_path {
283 if {$d_flag == "no"} {
284 if { [file exists $path/doxygen$exe] } {
285 catch { exec $path/doxygen -V } version_string
286 set version [lindex [split $version_string "\n"] 0]
287 puts "Info: $version "
288 puts " found in $path."
289 set doxy_path "$path/doxygen$exe"
293 if {$g_flag == "no"} {
294 if { [file exists $path/dot$exe] } {
295 catch { exec $path/dot -V } version
297 puts "Info: $version "
298 puts " found in $path."
299 set graph_path "$path/dot$exe"
303 if {$i_flag == "no"} {
304 if { [file exists $path/inkscape$exe] } {
305 catch { exec $path/inkscape -V } version
306 puts "Info: $version "
307 puts " found in $path."
308 set inkscape_path "$path/inkscape$exe"
312 if {$l_flag == "no"} {
313 if { [file exists $path/pdflatex$exe] } {
314 catch { exec $path/pdflatex -version } version
315 set version [lindex [split $version "\n"] 0]
316 puts "Info: $version "
317 puts " found in $path."
318 set latex_path "$path/pdflatex$exe"
325 # Check if tools have been found
326 if { $d_flag == "no" } {
327 puts "Warning: Could not find doxygen installed."
330 if { $g_flag == "no" } {
331 puts "Warning: Could not find graphviz installed."
333 if { $i_flag == "no" } {
334 puts "Warning: Could not find inkscape installed."
336 if { $l_flag == "no" } {
337 puts "Warning: Could not find pdflatex installed."
339 if { ("$::tcl_platform(platform)" == "windows") && ($h_flag == "no") } {
340 puts "Warning: Could not find hhc installed."
346 # Convert SVG files to PDF format to allow including them to PDF
347 # (requires InkScape to be in PATH)
348 proc OCCDoc_ProcessSvg {latexDir verboseMode} {
350 foreach file [glob -nocomplain $latexDir/*.svg] {
351 if {$verboseMode == "YES"} {
352 puts "Info: Converting file $file..."
354 set pdffile "[file rootname $file].pdf"
355 if { [catch {exec inkscape -z -D --file=$file --export-pdf=$pdffile} res] } {
362 # ==============================================
363 # Reference Manual-specific functions
364 # ==============================================
366 # Finds dependencies between all modules
367 proc OCCDoc_CreateModulesDependencyGraph {dir filename modules mpageprefix} {
368 global module_dependency
370 if {![catch {open $dir/$filename.dot "w"} file]} {
371 puts $file "digraph $filename"
374 foreach mod $modules {
378 puts $file "\t$mod \[ URL = \"[string tolower $mpageprefix$mod.html]\" \]"
379 foreach mod_depend $module_dependency($mod) {
380 puts $file "\t$mod_depend -> $mod \[ dir = \"back\", color = \"midnightblue\", style = \"solid\" \]"
391 # Finds dependencies between all toolkits in module
392 proc OCCDoc_CreateModuleToolkitsDependencyGraph {dir filename modulename tpageprefix} {
393 global toolkits_in_module
394 global toolkit_dependency
395 global toolkit_parent_module
397 if {![catch {open $dir/$filename.dot "w"} file]} {
398 puts $file "digraph $filename"
401 foreach tk $toolkits_in_module($modulename) {
402 puts $file "\t$tk \[ URL = \"[string tolower $tpageprefix$tk.html]\"\ ]"
403 foreach tkd $toolkit_dependency($tk) {
404 if { [info exists toolkit_parent_module($tkd)] } {
405 if {$toolkit_parent_module($tkd) == $modulename} {
406 puts $file "\t$tkd -> $tk \[ dir = \"back\", color = \"midnightblue\", style = \"solid\" \]"
419 # Finds dependencies between the current toolkit and other toolkits
420 proc OCCDoc_CreateToolkitDependencyGraph {dir filename toolkitname tpageprefix} {
421 global toolkit_dependency
423 if {![catch {open $dir/$filename.dot "w"} file]} {
424 puts $file "digraph $filename"
427 puts $file "\t$toolkitname \[ URL = \"[string tolower $tpageprefix$toolkitname.html]\"\, shape = box ]"
428 foreach tkd $toolkit_dependency($toolkitname) {
429 puts $file "\t$tkd \[ URL = \"[string tolower $tpageprefix$tkd.html]\"\ , shape = box ]"
430 puts $file "\t$toolkitname -> $tkd \[ color = \"midnightblue\", style = \"solid\" \]"
433 if {[llength $toolkit_dependency($toolkitname)] > 1} {
434 puts $file "\taspect = 1"
444 # Fills arrays of modules, toolkits, dependency of modules/toolkits etc
445 proc OCCDoc_LoadData { {theProductsDir ""} } {
446 global toolkits_in_module
447 global toolkit_dependency
448 global toolkit_parent_module
449 global module_dependency
451 if { $theProductsDir == ""} {
452 set modules_files [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $theProductsDir]/OS/" *.tcl]
454 set modules_files [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $theProductsDir]/VAS/" *.tcl]
457 foreach module_file $modules_files {
461 set modules [OCCDoc_GetModulesList $theProductsDir]
462 foreach mod $modules {
467 # Get toolkits of current module
468 set toolkits_in_module($mod) [$mod:toolkits]
469 # Get all dependence of current toolkit
470 foreach tk $toolkits_in_module($mod) {
471 # set parent module of current toolkit
472 set toolkit_parent_module($tk) $mod
473 set exlibfile [open "[OCCDoc_GetSourceDir $theProductsDir]/$tk/EXTERNLIB" r]
474 set exlibfile_data [read $exlibfile]
475 set exlibfile_data [split $exlibfile_data "\n"]
477 set toolkit_dependency($tk) {}
478 foreach dtk $exlibfile_data {
479 if { ([string first "TK" $dtk 0] == 0) ||
480 ([string first "P" $dtk 0] == 0) } {
481 lappend toolkit_dependency($tk) $dtk
488 # Get modules dependency
489 foreach mod $modules {
490 set module_dependency($mod) {}
491 foreach tk $toolkits_in_module($mod) {
492 foreach tkd $toolkit_dependency($tk) {
493 if { [info exists toolkit_parent_module($tkd)] } {
494 if { $toolkit_parent_module($tkd) != $mod &&
495 [lsearch $module_dependency($mod) $toolkit_parent_module($tkd)] == -1} {
496 lappend module_dependency($mod) $toolkit_parent_module($tkd)
504 # Returns list of packages of the given toolkit
505 proc OCCDoc_GetPackagesList { theToolKitPath } {
509 # Open file with list of packages of the given toolkit
510 set fileid [open "$theToolKitPath/PACKAGES" "r"]
512 while { [eof $fileid] == 0 } {
513 set str [gets $fileid]
515 lappend packages_list $str
521 return $packages_list
524 # Returns list of modules from UDLIST
525 proc OCCDoc_GetModulesList { {theProductsDir ""} } {
527 if { $theProductsDir == "" } {
528 source "[OCCDoc_GetSourceDir $theProductsDir]/OS/Modules.tcl"
529 # load a command from this file
530 set modules [OS:Modules]
532 source "[OCCDoc_GetSourceDir $theProductsDir]/VAS/Products.tcl"
533 # load a command from this file
534 set modules [VAS:Products]
535 set modules [lsearch -not -all -inline $modules "VAS"]
541 # Returns list of desired files in the specified location
542 proc OCCDoc_GetHeadersList { theDesiredContent thePackageName {theProductsDir ""} } {
544 # Get list of header files with path
545 set files_list [split [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $theProductsDir]/$thePackageName" "${thePackageName}.hxx" "${thePackageName}_*.hxx"]]
547 # Get content according to desired type ('p' for path and 'f' for filenames only)
548 if { $theDesiredContent == "p" } {
550 } elseif { $theDesiredContent == "f" } {
552 # Cut paths from filenames
553 foreach file $files_list {
554 set elem_index [lsearch $files_list $file]
555 lset files_list $elem_index [OCCDoc_GetNameFromPath [lindex $files_list $elem_index]]
561 # Returns location of the toolkit
562 proc OCCDoc_Locate { theToolKitName {theProductsDir ""} } {
563 set tk_dir "[OCCDoc_GetSourceDir $theProductsDir]/[OCCDoc_GetNameFromPath $theToolKitName]"
567 # Gets contents of the given html node (for Post-processing)
568 proc OCCDoc_GetNodeContents {node props html} {
569 set openTag "<$node$props>"
570 set closingTag "</$node>"
571 set start [string first $openTag $html]
575 set start [expr $start + [string length $openTag]]
576 set end [string length $html]
577 set html [string range $html $start $end]
578 set start [string first $closingTag $html]
579 set end [string length $html]
583 set start [expr $start - 1]
584 return [string range $html 0 $start]
587 # Generates main page file describing module structure
588 proc OCCDoc_MakeMainPage {outDir outFile modules {theProductsDir ""} } {
591 set one_module [expr [llength $modules] == 1]
592 set fd [open $outFile "w"]
594 set module_prefix "module_"
595 set toolkit_prefix "toolkit_"
596 set package_prefix "package_"
598 if { ! [file exists "$outDir/html"] } {
599 file mkdir "$outDir/html"
602 OCCDoc_LoadData $theProductsDir
604 # Main page: list of modules
605 if { ! $one_module } {
607 puts $fd "\\mainpage Open CASCADE Technology"
609 foreach mod $modules {
610 puts $fd "\\li \\subpage [string tolower $module_prefix$mod]"
612 # insert modules relationship diagramm
613 puts $fd "\\dotfile [OCCDoc_CreateModulesDependencyGraph $outDir/html schema_all_modules $modules $module_prefix]"
617 # One page per module: list of toolkits
619 foreach mod $modules {
625 puts $fd "\\mainpage OCCT Module [$mod:name]"
627 puts $fd "\\page [string tolower module_$mod] Module [$mod:name]"
629 foreach tk [lsort [$mod:toolkits]] {
631 puts $fd "\\li \\subpage [string tolower $toolkit_prefix$tk]"
633 puts $fd "\\dotfile [OCCDoc_CreateModuleToolkitsDependencyGraph $outDir/html schema_$mod $mod $toolkit_prefix]"
637 # One page per toolkit: list of packages
639 foreach tk $toolkits {
641 puts $fd "\\page [string tolower toolkit_$tk] Toolkit $tk"
642 foreach pk [lsort [OCCDoc_GetPackagesList [OCCDoc_Locate $tk $theProductsDir]]] {
644 set u [OCCDoc_GetNameFromPath $pk]
645 puts $fd "\\li \\subpage [string tolower $package_prefix$u]"
647 puts $fd "\\dotfile [OCCDoc_CreateToolkitDependencyGraph $outDir/html schema_$tk $tk $toolkit_prefix]"
651 # One page per package: list of classes
652 foreach pk $packages {
653 set u [OCCDoc_GetNameFromPath $pk]
655 puts $fd "\\page [string tolower $package_prefix$u] Package $u"
656 foreach hdr [lsort [OCCDoc_GetHeadersList "f" "$pk" "$theProductsDir"]] {
657 if { ! [regexp {^Handle_} $hdr] && [regexp {(.*)[.]hxx} $hdr str obj] } {
658 puts $fd "\\li \\subpage $obj"
669 # Parses generated files to add a navigation path
670 proc OCCDoc_PostProcessor {outDir} {
671 puts "[clock format [clock seconds] -format {%Y.%m.%d %H:%M}] Post-process is started ..."
672 append outDir "/html"
673 set files [glob -nocomplain -type f $outDir/package_*]
674 if { $files != {} } {
675 foreach f [lsort $files] {
676 set packageFilePnt [open $f r]
677 set packageFile [read $packageFilePnt]
678 set navPath [OCCDoc_GetNodeContents "div" " id=\"nav-path\" class=\"navpath\"" $packageFile]
679 set packageName [OCCDoc_GetNodeContents "div" " class=\"title\"" $packageFile]
680 regsub -all {<[^<>]*>} $packageName "" packageName
682 # add package link to nav path
683 set first [expr 1 + [string last "/" $f]]
684 set last [expr [string length $f] - 1]
685 set packageFileName [string range $f $first $last]
686 set end [string first "</ul>" $navPath]
687 set end [expr $end - 1]
688 set navPath [string range $navPath 0 $end]
689 append navPath " <li class=\"navelem\"><a class=\"el\" href=\"$packageFileName\">$packageName</a> </li>\n </ul>"
691 # get list of files to update
692 set listContents [OCCDoc_GetNodeContents "div" " class=\"textblock\"" $packageFile]
693 set listContents [OCCDoc_GetNodeContents "ul" "" $listContents]
694 set lines [split $listContents "\n"]
695 foreach line $lines {
696 if {[regexp {href=\"([^\"]*)\"} $line tmpLine classFileName]} {
697 # check if anchor is there
698 set anchorPos [string first "#" $classFileName]
699 if {$anchorPos != -1} {
700 set classFileName [string range $classFileName 0 [expr $anchorPos - 1]]
704 set classFilePnt [open $outDir/$classFileName r+]
705 set classFile [read $classFilePnt]
707 # find position of content block
708 set contentPos [string first "<div class=\"header\">" $classFile]
709 set navPart [string range $classFile 0 [expr $contentPos - 1]]
711 # position where to insert nav path
712 set posToInsert [string last "</div>" $navPart]
713 set prePart [string range $classFile 0 [expr $posToInsert - 1]]
714 set postPart [string range $classFile $posToInsert [string length $classFile]]
716 append newClassFile $prePart " <div id=\"nav-path\" class=\"navpath\">" $navPath \n " </div>" \n $postPart
718 # write updated content
720 puts $classFilePnt $newClassFile
724 close $packageFilePnt
728 puts "no files found"
733 # ======================================
734 # User Guides-specific functions
735 # ======================================
737 # Loads a list of docfiles from file FILES.txt
738 proc OCCDoc_LoadFilesList {} {
740 set INPUTDIR [OCCDoc_GetDoxDir]
742 global available_docfiles
743 set available_docfiles {}
745 # Read data from file
746 if { [file exists "$INPUTDIR/FILES_HTML.txt"] == 1 } {
747 set FILE [open "$INPUTDIR/FILES_HTML.txt" r]
749 set line [string trim [gets $FILE]]
751 # trim possible comments starting with '#'
752 set line [regsub {\#.*} $line {}]
754 lappend available_docfiles $line
768 # Read data from file
769 if { [file exists "$INPUTDIR/FILES_PDF.txt"] } {
770 set FILE [open "$INPUTDIR/FILES_PDF.txt" r]
772 set line [string trim [gets $FILE]]
774 # Trim possible comments starting with '#'
775 set line [regsub {\#.*} $line {}]
777 lappend available_pdf $line
790 # Writes new TeX file for conversion from tex to pdf for a specific doc
791 proc OCCDoc_MakeRefmanTex {fileName latexDir verboseMode latexFilesList} {
793 if { $verboseMode == "YES" } {
794 puts "Info: Making refman.tex file for $fileName..."
796 set DOCNAME "$latexDir/refman.tex"
797 if {[file exists $DOCNAME] == 1} {
798 file delete -force $DOCNAME
801 # Copy template file to latex folder
802 file copy "[OCCDoc_GetDoxDir]/resources/occt_pdf_template.tex" $DOCNAME
804 # Get templatized data
805 set texfile [open $DOCNAME "r"]
806 set texfile_loaded [read $texfile]
809 # Replace dummy values
810 set year [clock format [clock seconds] -format {%Y}]
811 set texfile [open $DOCNAME "w"]
812 set casVersion [OCCDoc_DetectCasVersion]
814 # Get name of the document
816 foreach aFileName $latexFilesList {
817 # Find the file in FILES_PDF.txt
818 set parsedFileName [split $aFileName "/" ]
819 set newfileName [string range $fileName [expr [string first "__" $fileName] + 2] end]
821 if { [lsearch -nocase $parsedFileName "$newfileName.md" ] != -1 } {
822 set filepath "[OCCDoc_GetDoxDir]/$aFileName"
823 if { [file exists $filepath] } {
824 set MDFile [open $filepath "r"]
825 set label [split [gets $MDFile] "\{"]
826 set docLabel [lindex $label 0]
834 set texfile_loaded [string map [list DEFDOCLABEL "$docLabel" DEFCASVERSION "$casVersion" DEFFILENAME "$fileName" DEFYEAR "$year"] $texfile_loaded]
837 puts $texfile $texfile_loaded
842 # Postprocesses generated TeX files
843 proc OCCDoc_ProcessTex {{texFiles {}} {latexDir} verboseMode} {
845 foreach TEX $texFiles {
846 if {$verboseMode == "YES"} {
847 puts "Info: Preprocessing file $TEX..."
850 if {![file exists $TEX]} {
851 puts "Error: file $TEX does not exist."
855 set IN_F [open "$TEX" "r"]
856 set TMPFILENAME "$latexDir/temp.tex"
857 set OUT_F [open $TMPFILENAME w]
860 set line [gets $IN_F]
861 if { [string first "\\includegraphics" $line] != -1 } {
862 # replace svg extension by pdf
863 set line [regsub {[.]svg} $line ".pdf"]
864 # Center images in TeX files
865 set line "\\begin{center}\n $line\n\\end{center}"
866 } elseif { [string first "\\subsection" $line] != -1 } {
867 # Replace \subsection with \section tag
868 regsub -all "\\\\subsection" $line "\\\\section" line
869 } elseif { [string first "\\subsubsection" $line] != -1 } {
870 # Replace \subsubsection with \subsection tag
871 regsub -all "\\\\subsubsection" $line "\\\\subsection" line
872 } elseif { [string first "\\paragraph" $line] != -1 } {
873 # Replace \paragraph with \subsubsection tag
874 regsub -all "\\\\paragraph" $line "\\\\subsubsection" line
885 file delete -force $TEX
886 file rename $TMPFILENAME $TEX