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 | ||||
| # | Time | Memory | Function | Location |
| 1 | 0.0001 | 54328 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 58032 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1410 | 13895044 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1420 | 13952948 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1786 | 14088312 | the_content( ) | ../single.php:16 |
| 6 | 0.1789 | 14090132 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1824 | 14094352 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1824 | 14094352 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1824 | 14094352 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.1824 | 14099940 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.1824 | 14099940 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:6 |
| 12 | 0.1928 | 14117212 | fread ( ) | ../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 | ||||
| # | Time | Memory | Function | Location |
| 1 | 0.0001 | 54328 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 58032 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1410 | 13895044 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1420 | 13952948 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1786 | 14088312 | the_content( ) | ../single.php:16 |
| 6 | 0.1789 | 14090132 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1824 | 14094352 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1824 | 14094352 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1824 | 14094352 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.1938 | 14115720 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.1938 | 14115720 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:1 |
| 12 | 0.2004 | 14116680 | fread ( ) | ../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 | ||||
| # | Time | Memory | Function | Location |
| 1 | 0.0001 | 54328 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 58032 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1410 | 13895044 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1420 | 13952948 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1786 | 14088312 | the_content( ) | ../single.php:16 |
| 6 | 0.1789 | 14090132 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1824 | 14094352 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1824 | 14094352 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1824 | 14094352 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.2008 | 14115716 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.2008 | 14115716 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:1 |
| 12 | 0.2079 | 14116696 | fread ( ) | ../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 | ||||
| # | Time | Memory | Function | Location |
| 1 | 0.0001 | 54328 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 58032 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1410 | 13895044 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1420 | 13952948 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1786 | 14088312 | the_content( ) | ../single.php:16 |
| 6 | 0.1789 | 14090132 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1824 | 14094352 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1824 | 14094352 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1824 | 14094352 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.2085 | 14116000 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.2085 | 14116000 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:3 |
| 12 | 0.2150 | 14117340 | fread ( ) | ../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 | ||||
| # | Time | Memory | Function | Location |
| 1 | 0.0001 | 54328 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 58032 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1410 | 13895044 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1420 | 13952948 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1786 | 14088312 | the_content( ) | ../single.php:16 |
| 6 | 0.1789 | 14090132 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1824 | 14094352 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1824 | 14094352 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1824 | 14094352 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.2154 | 14116052 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.2154 | 14116052 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:1 |
| 12 | 0.2222 | 14116964 | fread ( ) | ../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:
.
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.