Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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