Skip to content

Commit

Permalink
MDL-71240 filter_tex: Support paranoid mode for openin_any in latex
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies authored and Jenkins committed Sep 7, 2021
1 parent af4fb73 commit e514e69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions filter/tex/latex.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,22 @@ function render( $formula, $filename, $fontsize=12, $density=240, $background=''
$convertformat = 'png';
}
$filename = str_replace(".{$convertformat}", '', $filename);
$tex = "{$this->temp_dir}/$filename.tex";
$tex = "$filename.tex"; // Absolute paths won't work with openin_any = p setting.
$dvi = "{$this->temp_dir}/$filename.dvi";
$ps = "{$this->temp_dir}/$filename.ps";
$img = "{$this->temp_dir}/$filename.{$convertformat}";

// Change directory to temp dir so that we can work with relative paths.
chdir($this->temp_dir);

// turn the latex doc into a .tex file in the temp area
$fh = fopen( $tex, 'w' );
fputs( $fh, $doc );
fclose( $fh );

// run latex on document
$command = "$pathlatex --interaction=nonstopmode --halt-on-error $tex";
chdir( $this->temp_dir );

if ($this->execute($command, $log)) { // It allways False on Windows
// return false;
}
Expand Down
8 changes: 4 additions & 4 deletions filter/tex/texdebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,15 @@ function TexOutput($expression, $graphic=false) {
$output .= "<p>base filename for expression is '$md5'</p>\n";

// temporary paths
$tex = "$latex->temp_dir/$md5.tex";
$tex = "$md5.tex"; // Absolute paths won't work with openin_any = p setting.
$dvi = "$latex->temp_dir/$md5.dvi";
$ps = "$latex->temp_dir/$md5.ps";
$convertformat = get_config('filter_tex', 'convertformat');
$img = "$latex->temp_dir/$md5.{$convertformat}";

// Change directory to temp dir so that we can work with relative paths.
chdir($latex->temp_dir);

// put the expression as a file into the temp area
$expression = html_entity_decode($expression);
$output .= "<p>Processing TeX expression:</p><pre>$expression</pre>\n";
Expand All @@ -252,9 +255,6 @@ function TexOutput($expression, $graphic=false) {
fputs($fh, $doc);
fclose($fh);

// cd to temp dir
chdir($latex->temp_dir);

// step 1: latex command
$pathlatex = escapeshellarg($pathlatex);
$cmd = "$pathlatex --interaction=nonstopmode --halt-on-error $tex";
Expand Down

0 comments on commit e514e69

Please sign in to comment.