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.000153516{main}( )../index.php:0
20.000256956require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.140513846160require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.141313908752include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.177914023068the_content( )../single.php:16
60.178214024932apply_filters( )../post-template.php:167
70.181414029484call_user_func_array ( )../plugin.php:166
80.181414029668vim_color( )../plugin.php:0
90.181414030004preg_replace ( )../wp-vimcolor.php:143
100.181414036240preg_replace ( )../wp-vimcolor.php:143
110.181414036444vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:6
120.188614052832fread ( )../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.000153516{main}( )../index.php:0
20.000256956require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.140513846160require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.141313908752include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.177914023068the_content( )../single.php:16
60.178214024932apply_filters( )../post-template.php:167
70.181414029484call_user_func_array ( )../plugin.php:166
80.181414029668vim_color( )../plugin.php:0
90.181414030004preg_replace ( )../wp-vimcolor.php:143
100.189514050776preg_replace ( )../wp-vimcolor.php:143
110.189514050920vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.194614052356fread ( )../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.000153516{main}( )../index.php:0
20.000256956require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.140513846160require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.141313908752include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.177914023068the_content( )../single.php:16
60.178214024932apply_filters( )../post-template.php:167
70.181414029484call_user_func_array ( )../plugin.php:166
80.181414029668vim_color( )../plugin.php:0
90.181414030004preg_replace ( )../wp-vimcolor.php:143
100.194914050784preg_replace ( )../wp-vimcolor.php:143
110.194914050932vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.199614052372fread ( )../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.000153516{main}( )../index.php:0
20.000256956require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.140513846160require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.141313908752include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.177914023068the_content( )../single.php:16
60.178214024932apply_filters( )../post-template.php:167
70.181414029484call_user_func_array ( )../plugin.php:166
80.181414029668vim_color( )../plugin.php:0
90.181414030004preg_replace ( )../wp-vimcolor.php:143
100.200214051080preg_replace ( )../wp-vimcolor.php:143
110.200214051296vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:3
120.205014053136fread ( )../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.000153516{main}( )../index.php:0
20.000256956require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.140513846160require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.141313908752include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' )../template-loader.php:34
50.177914023068the_content( )../single.php:16
60.178214024932apply_filters( )../post-template.php:167
70.181414029484call_user_func_array ( )../plugin.php:166
80.181414029668vim_color( )../plugin.php:0
90.181414030004preg_replace ( )../wp-vimcolor.php:143
100.205414051044preg_replace ( )../wp-vimcolor.php:143
110.205414051188vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.210514052624fread ( )../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