Created
October 16, 2018 09:36
-
-
Save tochikuji/60ec60e774f7de3542f9aab57c1a44ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use File::Slurp qw/read_file/; | |
use feature qw/say/; | |
my $main_file = shift @ARGV; | |
my @paths = @ARGV; | |
my @main_source = read_file $main_file; | |
for(my $i = 0; $i < $#main_source; ++$i){ | |
my $line = $main_source[$i]; | |
if($line =~ m/\\(?:include|input)\{(.+?)\}/){ | |
my $input_filename = $1; | |
unless($input_filename =~ m/\.tex\s*$/i){ | |
$input_filename .= '.tex'; | |
} | |
my @input_source = read_file $input_filename; | |
splice @main_source, $i, 1, @input_source; | |
$i += $#input_source; | |
} | |
} | |
say @main_source; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment