Skip to content

Commit

Permalink
Merge pull request #243 from janniklasrose/import
Browse files Browse the repository at this point in the history
Support for additional macros from import package
  • Loading branch information
ftilmann authored Dec 26, 2021
2 parents 4edc359 + bd4aee4 commit 3fb53cd
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
17 changes: 10 additions & 7 deletions latexdiff
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,7 @@ sub remove_endinput {
# expands \input and \include commands within text
# expands \bibliography command with corresponding bbl file if available
# expands \subfile command (from subfiles package - not part of standard text distribution)
# expands \import etc commands (from import package - not part of standard text distribution)
# preamble is scanned for includeonly commands
# encoding is the encoding
sub flatten {
Expand Down Expand Up @@ -1644,15 +1645,16 @@ sub flatten {
# Run through filter, to let filterscript have a pass if it was set
$text = filter($text);

# Recursively replace \\import and \\subimport files
$text =~ s/(^(?:[^%\n]|\\%)*)(\\subimport\{(.*?)\}|\\import\{(.*?)\})(?:[\s]*)\{(.*?)\}/{
# Recursively replace \\import, \\subimport, and related import commands
$text =~ s/(^(?:[^%\n]|\\%)*)(\\(sub)?(?:import|inputfrom|includefrom))\{(.*?)\}(?:[\s]*)\{(.*?)\}/{
# (--------1-------)(--(=3=)-------------2-------------------) (-4-) (-5-)
# $1 is begline
# $3 is directory if subimport
# $4 is directory if import
# $2 is the import macro name
# $3 is (optional) prefix "sub"
# $4 is directory
# $5 is filename
$begline = (defined($1)? $1 : "");
$subdir = $3 if defined($3);
$subdir = $4 if defined($4);
$subdir = $4;
$fname = $5;
$fname .= ".tex" unless $fname =~ m|\.\w{3,4}$|;
print STDERR "DEBUG begline:", $begline, "\n" if $debug;
Expand All @@ -1667,12 +1669,13 @@ sub flatten {
print STDERR "importing importfilepath:", $importfilepath,"\n" if $verbose;
if ( -f $importfilepath ) {
# If file exists, replace input or include command with expanded input
#TODO: need remove_endinput & newpage similar to other replacements inside flatten
$replacement=flatten(read_file_with_encoding($importfilepath, $encoding), $preamble,$importfilepath,$encoding) or die "Could not open file ",$fullfile,": $!";
} else {
# if file does not exist, do not expand include or input command (do not warn if fname contains #[0-9] as it is then likely part of a command definition
# and is not meant to be expanded directly
print STDERR "WARNING: Could not find included file ",$importfilepath,". I will continue but not expand |$2|\n";
$replacement=(defined($3)? "\\subimport" : "\\import");
$replacement = $2;
$replacement .= "{$subdir}{$fname} % Processed";
}
"$begline$replacement";
Expand Down
1 change: 1 addition & 0 deletions testsuite/import-level0/import-level1/world.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
World!
5 changes: 5 additions & 0 deletions testsuite/import-level0/include-me.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hello, \subimport{import-level1}{world}

Hello, \subinputfrom{import-level1}{world}

% Hello, \subincludefrom{import-level1}{world} % cannot nest include's
5 changes: 5 additions & 0 deletions testsuite/import-level0/input-me.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hello, \subimport{import-level1}{world}

Hello, \subinputfrom{import-level1}{world}

Hello, \subincludefrom{import-level1}{world}
9 changes: 9 additions & 0 deletions testsuite/import-new.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\documentclass[10pt]{article}
\usepackage{import}
\begin{document}
\import{import-level0}{input-me}
\inputfrom{import-level0}{input-me}
\includefrom{import-level0}{include-me}

some additional text only in new file
\end{document}
7 changes: 7 additions & 0 deletions testsuite/import-old.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\documentclass[10pt]{article}
\usepackage{import}
\begin{document}
\import{import-level0}{input-me}
\inputfrom{import-level0}{input-me}
\includefrom{import-level0}{include-me}
\end{document}
2 changes: 1 addition & 1 deletion testsuite/verify
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set bodydiff=0
set testroots=( test rapine_et_al island_obs2004 texdiffsample gershwin12 "gershwin34 --graphics-markup=none" example utf \
delequ latin9 pollack move-equation nomarkup subscript doubledollar intertext \
DIFDELCMDBUG eqnarray eqnarray2 subscriptm delequ2 schneider gennady umesh underwood endfloat endfloat2 outerrise \
delequ3 delequ4 "simplefrac --allow-spaces" "master --flatten" "subfile --flatten" titlediffTest2 exampleDiff bornd2 \
delequ3 delequ4 "simplefrac --allow-spaces" "master --flatten" "subfile --flatten" "import --flatten" titlediffTest2 exampleDiff bornd2 \
"rolla --math-markup=2" mini "complex-maths --math-markup=1" margalit circonflex mwe-comment "apacite-test --flatten" quoteddollarunderscore units complicated-math move-equation2 lists "figures --graphics-markup=both" alignat "safecmd --append-safecmd=remark" verbatim verbatim2-is143 embedded-math-array "verbatim-input --flatten" anchordemo 'customdiffcmdtest --add-to-config "CUSTOMDIFCMD=blindtext;mypar;donothing;cmd"' description frac_w_space_comments \
"href-in-bibliography --append-safecmd=path" revtex-bibliography biblatex 'txtcmd-with-multiple-arguments --append-textcmd=cmd' \
)
Expand Down

0 comments on commit 3fb53cd

Please sign in to comment.