Skip to content

Instantly share code, notes, and snippets.

@tochikuji
Created October 16, 2018 09:36
Show Gist options
  • Save tochikuji/60ec60e774f7de3542f9aab57c1a44ff to your computer and use it in GitHub Desktop.
Save tochikuji/60ec60e774f7de3542f9aab57c1a44ff to your computer and use it in GitHub Desktop.
#!/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