Passing Command Line Arguments to a LaTeX Document


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154328{main}( )../index.php:0
20.000258032require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.141013895044require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.142013952948include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.178614088312the_content( )../single.php:16
60.178914090132apply_filters( )../post-template.php:167
70.182414094352call_user_func_array ( )../plugin.php:166
80.182414094352vim_color( )../plugin.php:0
90.182414094352preg_replace ( )../wp-vimcolor.php:143
100.182414099940preg_replace ( )../wp-vimcolor.php:143
110.182414099940vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:6
120.192814117212fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154328{main}( )../index.php:0
20.000258032require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.141013895044require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.142013952948include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.178614088312the_content( )../single.php:16
60.178914090132apply_filters( )../post-template.php:167
70.182414094352call_user_func_array ( )../plugin.php:166
80.182414094352vim_color( )../plugin.php:0
90.182414094352preg_replace ( )../wp-vimcolor.php:143
100.193814115720preg_replace ( )../wp-vimcolor.php:143
110.193814115720vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.200414116680fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154328{main}( )../index.php:0
20.000258032require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.141013895044require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.142013952948include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.178614088312the_content( )../single.php:16
60.178914090132apply_filters( )../post-template.php:167
70.182414094352call_user_func_array ( )../plugin.php:166
80.182414094352vim_color( )../plugin.php:0
90.182414094352preg_replace ( )../wp-vimcolor.php:143
100.200814115716preg_replace ( )../wp-vimcolor.php:143
110.200814115716vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.207914116696fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154328{main}( )../index.php:0
20.000258032require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.141013895044require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.142013952948include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.178614088312the_content( )../single.php:16
60.178914090132apply_filters( )../post-template.php:167
70.182414094352call_user_func_array ( )../plugin.php:166
80.182414094352vim_color( )../plugin.php:0
90.182414094352preg_replace ( )../wp-vimcolor.php:143
100.208514116000preg_replace ( )../wp-vimcolor.php:143
110.208514116000vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:3
120.215014117340fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154328{main}( )../index.php:0
20.000258032require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.141013895044require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.142013952948include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.178614088312the_content( )../single.php:16
60.178914090132apply_filters( )../post-template.php:167
70.182414094352call_user_func_array ( )../plugin.php:166
80.182414094352vim_color( )../plugin.php:0
90.182414094352preg_replace ( )../wp-vimcolor.php:143
100.215414116052preg_replace ( )../wp-vimcolor.php:143
110.215414116052vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.222214116964fread ( )../wp-vimcolor.php:105

Some time ago, someone asked me if I knew a way to pass command line arguments to LaTeX documents. My first response was that this ought to be impossible; being a compiler, LaTeX cannot in any way alter it’s input files. But command line parameters can alter the output without touching the input of course.

This has kept me thinking for a while, and at the end I came up with some kind of a solution.

Let’s take a simple LaTeX file:

and call it .

We will define the output of as a command line parameter at LaTeX invocation, as follows:

Result: containing the text “hello world”. Admitted, it’s not the easiest solution, but it does make LaTeX useful inside simple batch jobs!

For more advanced LaTeX templating, I advise using Perl and Text::Template.

Add a Comment   Trackback  

Add a Comment