Changeset 489013
- Timestamp:
- 01/12/2012 09:22:27 PM (14 years ago)
- Location:
- latex-everything/trunk
- Files:
-
- 1 added
- 2 deleted
- 2 edited
-
article-to-latex.php (modified) (8 diffs)
-
default-template.php (modified) (1 diff)
-
html-to-latex.php (added)
-
html2latex.pl (deleted)
-
perl5/HTML/Latex.pm (deleted)
Legend:
- Unmodified
- Added
- Removed
-
latex-everything/trunk/article-to-latex.php
r489012 r489013 4 4 Plugin URI: 5 5 Version: 0.1 6 Author: D evon Buchanan7 Author URI: 6 Author: Divinenephron (Devon Buchanan) 7 Author URI: http://divinenephron.co.uk 8 8 Description: 9 9 License: GPL … … 17 17 18 18 define( 'PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); // Plugin directory with trailing slash 19 define( 'HTML_TO_LATEX_SCRIPT', PLUGIN_DIR . 'html2latex.pl' );20 19 define( 'PDFLATEX', '/usr/texbin/pdflatex' ); 21 20 22 23 class Divinenephron_Article_To_Latex { 21 include('html-to-latex.php'); // Include functions to convert html to latex. 22 23 24 class A2l_Article_To_Latex { 24 25 25 26 var $post; … … 84 85 85 86 // Open and write the latex the temporary file. 86 if ( !$f = @fopen( $this->latex_file, 'w' ) ) 87 if ( !WP_DEBUG ) 88 $f = @fopen( $this->latex_file, 'w' ); 89 else 90 $f = fopen( $this->latex_file, 'w' ); 91 if ( !$f ) 87 92 return new WP_Error( 'fopen', 'Could not open temporary file for writing' ); 88 if ( false === @fwrite($f, $latex) ) 93 if ( ! WP_DEBUG ) 94 $w = @fwrite($f, $latex); 95 else 96 $w = fwrite($f, $latex); 97 if ( !$w ) 89 98 return new WP_Error( 'fwrite', 'Could not write to temporary file' ); 90 99 fclose($f); … … 99 108 } 100 109 return $template; 101 // TODO: Add a default template in the plugin directory.102 110 } 103 111 … … 105 113 $tmp_file = tempnam( '/tmp', 'atl'); // Falls back on system temp dir 106 114 $dir = dirname( $this->latex_file ); 115 116 // Tell Latex to search in the theme directory for class/style files. 117 putenv('TEXINPUTS=.:' . get_stylesheet_directory() . ':' . get_template_directory() . ':'); 107 118 $cmd = sprintf( 'cd %s; %s --interaction=nonstopmode %s 2>&1', $dir, PDFLATEX, $this->latex_file); 108 119 … … 191 202 if ( get_post_type( $post_id ) == 'post' && !wp_is_post_revision( $post_id ) ) { 192 203 global $a2l; 193 $a2l = new Divinenephron_Article_To_Latex( $post_id );204 $a2l = new A2l_Article_To_Latex( $post_id ); 194 205 $a2l->create_pdf(); 195 206 } … … 206 217 $post_id = $_GET[ 'a2l_error' ]; 207 218 global $a2l; 208 $a2l = new Divinenephron_Article_To_Latex( $post_id );219 $a2l = new A2l_Article_To_Latex( $post_id ); 209 220 $a2l->create_pdf(); 210 221 } … … 213 224 214 225 215 /* Helper functions that converts html (e.g. from the_content() ) into LaTeX. 216 */ 217 function a2l_latex ( $html ) { 218 $latex = a2l_get_latex( $html ); 219 if ( is_wp_error( $latex ) ) { 220 print "Error: {$latex->get_error_message()}"; 221 } else { 222 print $latex; 223 } 224 } 225 226 function a2l_get_latex ( $html ) { 227 // Get the name of a temporary file. 228 if ( !$html_file = tempnam( sys_get_temp_dir(), 'a2l-' ) ) // Should fall back on system's temp dir if /tmp does not exist 229 return new WP_Error( 'tempnam', 'Could not create temporary file.' ); 230 $dir = dirname( $html_file ); 231 232 // Open and write the html the temporary file. 233 if ( !$f = @fopen( $html_file, 'w' ) ) 234 return new WP_Error( 'fopen', 'Could not open temporary file for writing' ); 235 if ( false === @fwrite($f, $html) ) 236 return new WP_Error( 'fwrite', 'Could not write to temporary file' ); 237 fclose($f); 238 239 // Convert the temporary file to using html2latex.pl (the latex is put into its stdout) 240 $cmd = sprintf( 'cd %s; perl %s %s 2>/dev/null', $dir, HTML_TO_LATEX_SCRIPT, $html_file ); 241 exec( $cmd, $h2l_output, $v ); 242 $latex = implode( "\n", $h2l_output ); 243 if ( $v != 0 ) { // There was an error 244 return new WP_Error('html2latex.pl', $latex); 245 } 246 247 unlink( $html_file ); 248 249 return $latex; 250 } 226 -
latex-everything/trunk/default-template.php
r489012 r489013 16 16 \maketitle 17 17 18 <?php a2l_latex( apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file ))) ?>18 <?php html_to_latex( apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file ))) ?> 19 19 20 20 \end{document}
Note: See TracChangeset
for help on using the changeset viewer.