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 | 53516 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 56956 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1405 | 13846160 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1413 | 13908752 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1779 | 14023068 | the_content( ) | ../single.php:16 |
| 6 | 0.1782 | 14024932 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1814 | 14029484 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1814 | 14029668 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1814 | 14030004 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.1814 | 14036240 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.1814 | 14036444 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:6 |
| 12 | 0.1886 | 14052832 | 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 | 53516 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 56956 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1405 | 13846160 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1413 | 13908752 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1779 | 14023068 | the_content( ) | ../single.php:16 |
| 6 | 0.1782 | 14024932 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1814 | 14029484 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1814 | 14029668 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1814 | 14030004 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.1895 | 14050776 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.1895 | 14050920 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:1 |
| 12 | 0.1946 | 14052356 | 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 | 53516 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 56956 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1405 | 13846160 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1413 | 13908752 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1779 | 14023068 | the_content( ) | ../single.php:16 |
| 6 | 0.1782 | 14024932 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1814 | 14029484 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1814 | 14029668 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1814 | 14030004 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.1949 | 14050784 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.1949 | 14050932 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:1 |
| 12 | 0.1996 | 14052372 | 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 | 53516 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 56956 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1405 | 13846160 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1413 | 13908752 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1779 | 14023068 | the_content( ) | ../single.php:16 |
| 6 | 0.1782 | 14024932 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1814 | 14029484 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1814 | 14029668 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1814 | 14030004 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.2002 | 14051080 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.2002 | 14051296 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:3 |
| 12 | 0.2050 | 14053136 | 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 | 53516 | {main}( ) | ../index.php:0 |
| 2 | 0.0002 | 56956 | require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' ) | ../index.php:17 |
| 3 | 0.1405 | 13846160 | require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' ) | ../wp-blog-header.php:16 |
| 4 | 0.1413 | 13908752 | include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/single.php' ) | ../template-loader.php:34 |
| 5 | 0.1779 | 14023068 | the_content( ) | ../single.php:16 |
| 6 | 0.1782 | 14024932 | apply_filters( ) | ../post-template.php:167 |
| 7 | 0.1814 | 14029484 | call_user_func_array ( ) | ../plugin.php:166 |
| 8 | 0.1814 | 14029668 | vim_color( ) | ../plugin.php:0 |
| 9 | 0.1814 | 14030004 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 10 | 0.2054 | 14051044 | preg_replace ( ) | ../wp-vimcolor.php:143 |
| 11 | 0.2054 | 14051188 | vimcolor_process_color( ) | ../wp-vimcolor.php(143) : regexp code:1 |
| 12 | 0.2105 | 14052624 | 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.