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]
539 # Returns list of desired files in the specified location
540 proc OCCDoc_GetHeadersList { theDesiredContent thePackageName {theProductsDir ""} } {
542 # Get list of header files with path
543 set files_list [split [glob -nocomplain -type f -directory "[OCCDoc_GetIncDir $theProductsDir]" "${thePackageName}.hxx" "${thePackageName}_*.hxx"]]
545 # Get content according to desired type ('p' for path and 'f' for filenames only)
546 if { $theDesiredContent == "p" } {
548 } elseif { $theDesiredContent == "f" } {
550 # Cut paths from filenames
551 foreach file $files_list {
552 set elem_index [lsearch $files_list $file]
553 lset files_list $elem_index [OCCDoc_GetNameFromPath [lindex $files_list $elem_index]]
559 # Returns location of the toolkit
560 proc OCCDoc_Locate { theToolKitName {theProductsDir ""} } {
561 set tk_dir "[OCCDoc_GetSourceDir $theProductsDir]/[OCCDoc_GetNameFromPath $theToolKitName]"
565 # Gets contents of the given html node (for Post-processing)
566 proc OCCDoc_GetNodeContents {node props html} {
567 set openTag "<$node$props>"
568 set closingTag "</$node>"
569 set start [string first $openTag $html]
573 set start [expr $start + [string length $openTag]]
574 set end [string length $html]
575 set html [string range $html $start $end]
576 set start [string first $closingTag $html]
577 set end [string length $html]
581 set start [expr $start - 1]
582 return [string range $html 0 $start]
585 # Generates main page file describing module structure
586 proc OCCDoc_MakeMainPage {outDir outFile modules {theProductsDir ""} } {
589 set one_module [expr [llength $modules] == 1]
590 set fd [open $outFile "w"]
592 set module_prefix "module_"
593 set toolkit_prefix "toolkit_"
594 set package_prefix "package_"
596 if { ! [file exists "$outDir/html"] } {
597 file mkdir "$outDir/html"
600 OCCDoc_LoadData $theProductsDir
602 # Main page: list of modules
603 if { ! $one_module } {
605 puts $fd "\\mainpage Open CASCADE Technology"
607 foreach mod $modules {
608 puts $fd "\\li \\subpage [string tolower $module_prefix$mod]"
610 # insert modules relationship diagramm
611 puts $fd "\\dotfile [OCCDoc_CreateModulesDependencyGraph $outDir/html schema_all_modules $modules $module_prefix]"
615 # One page per module: list of toolkits
617 foreach mod $modules {
623 puts $fd "\\mainpage OCCT Module [$mod:name]"
625 puts $fd "\\page [string tolower module_$mod] Module [$mod:name]"
627 foreach tk [lsort [$mod:toolkits]] {
629 puts $fd "\\li \\subpage [string tolower $toolkit_prefix$tk]"
631 puts $fd "\\dotfile [OCCDoc_CreateModuleToolkitsDependencyGraph $outDir/html schema_$mod $mod $toolkit_prefix]"
635 # One page per toolkit: list of packages
637 foreach tk $toolkits {
639 puts $fd "\\page [string tolower toolkit_$tk] Toolkit $tk"
640 foreach pk [lsort [OCCDoc_GetPackagesList [OCCDoc_Locate $tk $theProductsDir]]] {
642 set u [OCCDoc_GetNameFromPath $pk]
643 puts $fd "\\li \\subpage [string tolower $package_prefix$u]"
645 puts $fd "\\dotfile [OCCDoc_CreateToolkitDependencyGraph $outDir/html schema_$tk $tk $toolkit_prefix]"
649 # One page per package: list of classes
650 foreach pk $packages {
651 set u [OCCDoc_GetNameFromPath $pk]
653 puts $fd "\\page [string tolower $package_prefix$u] Package $u"
654 foreach hdr [lsort [OCCDoc_GetHeadersList "f" "$pk" "$theProductsDir"]] {
655 if { ! [regexp {^Handle_} $hdr] && [regexp {(.*)[.]hxx} $hdr str obj] } {
656 puts $fd "\\li \\subpage $obj"
667 # Parses generated files to add a navigation path
668 proc OCCDoc_PostProcessor {outDir} {
669 puts "[clock format [clock seconds] -format {%Y.%m.%d %H:%M}] Post-process is started ..."
670 append outDir "/html"
671 set files [glob -nocomplain -type f $outDir/package_*]
672 if { $files != {} } {
673 foreach f [lsort $files] {
674 set packageFilePnt [open $f r]
675 set packageFile [read $packageFilePnt]
676 set navPath [OCCDoc_GetNodeContents "div" " id=\"nav-path\" class=\"navpath\"" $packageFile]
677 set packageName [OCCDoc_GetNodeContents "div" " class=\"title\"" $packageFile]
678 regsub -all {<[^<>]*>} $packageName "" packageName
680 # add package link to nav path
681 set first [expr 1 + [string last "/" $f]]
682 set last [expr [string length $f] - 1]
683 set packageFileName [string range $f $first $last]
684 set end [string first "</ul>" $navPath]
685 set end [expr $end - 1]
686 set navPath [string range $navPath 0 $end]
687 append navPath " <li class=\"navelem\"><a class=\"el\" href=\"$packageFileName\">$packageName</a> </li>\n </ul>"
689 # get list of files to update
690 set listContents [OCCDoc_GetNodeContents "div" " class=\"textblock\"" $packageFile]
691 set listContents [OCCDoc_GetNodeContents "ul" "" $listContents]
692 set lines [split $listContents "\n"]
693 foreach line $lines {
694 if {[regexp {href=\"([^\"]*)\"} $line tmpLine classFileName]} {
695 # check if anchor is there
696 set anchorPos [string first "#" $classFileName]
697 if {$anchorPos != -1} {
698 set classFileName [string range $classFileName 0 [expr $anchorPos - 1]]
702 set classFilePnt [open $outDir/$classFileName r+]
703 set classFile [read $classFilePnt]
705 # find position of content block
706 set contentPos [string first "<div class=\"header\">" $classFile]
707 set navPart [string range $classFile 0 [expr $contentPos - 1]]
709 # position where to insert nav path
710 set posToInsert [string last "</div>" $navPart]
711 set prePart [string range $classFile 0 [expr $posToInsert - 1]]
712 set postPart [string range $classFile $posToInsert [string length $classFile]]
714 append newClassFile $prePart " <div id=\"nav-path\" class=\"navpath\">" $navPath \n " </div>" \n $postPart
716 # write updated content
718 puts $classFilePnt $newClassFile
722 close $packageFilePnt
726 puts "no files found"
731 # ======================================
732 # User Guides-specific functions
733 # ======================================
735 # Loads a list of docfiles from file FILES.txt
736 proc OCCDoc_LoadFilesList {} {
738 set INPUTDIR [OCCDoc_GetDoxDir]
740 global available_docfiles
741 set available_docfiles {}
743 # Read data from file
744 if { [file exists "$INPUTDIR/FILES_HTML.txt"] == 1 } {
745 set FILE [open "$INPUTDIR/FILES_HTML.txt" r]
747 set line [string trim [gets $FILE]]
749 # trim possible comments starting with '#'
750 set line [regsub {\#.*} $line {}]
752 lappend available_docfiles $line
766 # Read data from file
767 if { [file exists "$INPUTDIR/FILES_PDF.txt"] } {
768 set FILE [open "$INPUTDIR/FILES_PDF.txt" r]
770 set line [string trim [gets $FILE]]
772 # Trim possible comments starting with '#'
773 set line [regsub {\#.*} $line {}]
775 lappend available_pdf $line
788 # Writes new TeX file for conversion from tex to pdf for a specific doc
789 proc OCCDoc_MakeRefmanTex {fileName latexDir verboseMode latexFilesList} {
791 if { $verboseMode == "YES" } {
792 puts "Info: Making refman.tex file for $fileName..."
794 set DOCNAME "$latexDir/refman.tex"
795 if {[file exists $DOCNAME] == 1} {
796 file delete -force $DOCNAME
799 # Copy template file to latex folder
800 file copy "[OCCDoc_GetDoxDir]/resources/occt_pdf_template.tex" $DOCNAME
802 # Get templatized data
803 set texfile [open $DOCNAME "r"]
804 set texfile_loaded [read $texfile]
807 # Replace dummy values
808 set year [clock format [clock seconds] -format {%Y}]
809 set texfile [open $DOCNAME "w"]
810 set casVersion [OCCDoc_DetectCasVersion]
812 # Get name of the document
814 foreach aFileName $latexFilesList {
815 # Find the file in FILES_PDF.txt
816 set parsedFileName [split $aFileName "/" ]
817 set newfileName [string range $fileName [expr [string first "__" $fileName] + 2] end]
819 if { [lsearch -nocase $parsedFileName "$newfileName.md" ] != -1 } {
820 set filepath "[OCCDoc_GetDoxDir]/$aFileName"
821 if { [file exists $filepath] } {
822 set MDFile [open $filepath "r"]
823 set label [split [gets $MDFile] "\{"]
824 set docLabel [lindex $label 0]
832 set texfile_loaded [string map [list DEFDOCLABEL "$docLabel" DEFCASVERSION "$casVersion" DEFFILENAME "$fileName" DEFYEAR "$year"] $texfile_loaded]
835 puts $texfile $texfile_loaded
840 # Postprocesses generated TeX files
841 proc OCCDoc_ProcessTex {{texFiles {}} {latexDir} verboseMode} {
843 foreach TEX $texFiles {
844 if {$verboseMode == "YES"} {
845 puts "Info: Preprocessing file $TEX..."
848 if {![file exists $TEX]} {
849 puts "Error: file $TEX does not exist."
853 set IN_F [open "$TEX" "r"]
854 set TMPFILENAME "$latexDir/temp.tex"
855 set OUT_F [open $TMPFILENAME w]
858 set line [gets $IN_F]
859 if { [string first "\\includegraphics" $line] != -1 } {
860 # replace svg extension by pdf
861 set line [regsub {[.]svg} $line ".pdf"]
862 # Center images in TeX files
863 set line "\\begin{center}\n $line\n\\end{center}"
864 } elseif { [string first "\\subsection" $line] != -1 } {
865 # Replace \subsection with \section tag
866 regsub -all "\\\\subsection" $line "\\\\section" line
867 } elseif { [string first "\\subsubsection" $line] != -1 } {
868 # Replace \subsubsection with \subsection tag
869 regsub -all "\\\\subsubsection" $line "\\\\subsection" line
870 } elseif { [string first "\\paragraph" $line] != -1 } {
871 # Replace \paragraph with \subsubsection tag
872 regsub -all "\\\\paragraph" $line "\\\\subsubsection" line
883 file delete -force $TEX
884 file rename $TMPFILENAME $TEX