| 1 |
#!/usr/bin/env perl |
| 2 |
# latexrevise - takes output file of latexdiff and removes either discarded |
| 3 |
# or appended passages, then deletes all other latexdiff markup |
| 4 |
# |
| 5 |
# Copyright (C) 2004 F J Tilmann ([email protected]) |
| 6 |
# |
| 7 |
# Repository: https://github.com/ftilmann/latexdiff |
| 8 |
# CTAN page: http://www.ctan.org/pkg/latexdiff |
| 9 |
# |
| 10 |
# This program is free software: you can redistribute it and/or modify |
| 11 |
# it under the terms of the GNU General Public License as published by |
| 12 |
# the Free Software Foundation, either version 3 of the License, or |
| 13 |
# (at your option) any later version. |
| 14 |
# |
| 15 |
# This program is distributed in the hope that it will be useful, |
| 16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
# GNU General Public License for more details. |
| 19 |
# You should have received a copy of the GNU General Public License |
| 20 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
# |
| 22 |
# Detailed usage information at the end of the file |
| 23 |
# Note: version number now keeping up with latexdiff |
| 24 |
# Version 1.3.2 |
| 25 |
# - Functionality -c option: if comment to be deleted is the last in the line replace new line by space character. This is done to avoid errors or unintended line breaks from empty lines after deletion (which are implicit \par) |
| 26 |
# - Introduce option -r / --replace which removes markup of the form \replaced{new text}{old text} in the changes package |
| 27 |
# Version 1.3.1 (Bug fix) Remove some deprecation warnings due to uncommented left parentheses |
| 28 |
# Version 1.0.2 Option --version |
| 29 |
# Version 1.0.1 no changes to latexrevise |
| 30 |
# Version 0.3 Updated for compatibility with latexdiff 0.3 output (DIFAUXCMD removal) |
| 31 |
# Version 0.1 First public release |
| 32 |
|
| 33 |
use Getopt::Long; |
| 34 |
use strict; |
| 35 |
use warnings; |
| 36 |
|
| 37 |
my $versionstring = <<EOF ; |
| 38 |
This is LATEXREVISE 1.3.2 |
| 39 |
(c) 2005-2021 F J Tilmann |
| 40 |
EOF |
| 41 |
|
| 42 |
# Markup strings (make sure that this are set to the same value as in |
| 43 |
# latexdiff) |
| 44 |
# If at all possible, do not change these as parts of the program |
| 45 |
# depend on the actual name. |
| 46 |
# At the very least adapt subroutine postprocess to new tokens. |
| 47 |
|
| 48 |
# note: have to use three backslashes to mean one literal one (reason |
| 49 |
# unknown |
| 50 |
my $ADDMARKOPEN = '\\\DIFaddbegin(?:FL)? '; # Token to mark begin of appended text |
| 51 |
my $ADDMARKCLOSE = '\\\DIFaddend(?:FL)?(?: |\z)'; # Token to mark end of appended text (|\z only deals with the case of \DIFaddend right before \end{document} |
| 52 |
my $ADDOPEN = '\\\DIFadd(?:FL)?{'; # To mark begin of added text passage |
| 53 |
my $ADDCLOSE = '}'; # To mark end of added text passage |
| 54 |
my $ADDCOMMENT = 'DIF > '; # To mark added comment line |
| 55 |
my $DELMARKOPEN = '\\\DIFdelbegin(?:FL)? '; # Token to mark begin of deleted text |
| 56 |
my $DELMARKCLOSE = '\\\DIFdelend(?:FL)?(?: |\z)'; # Token to mark end of deleted text |
| 57 |
my $DELOPEN = '\\\DIFdel(?:FL)?{'; # To mark begin of deleted text passage |
| 58 |
my $DELCLOSE = '}'; # To mark end of deleted text passage |
| 59 |
my $ALTEXT = 'FL'; # string which might be appended to above commands |
| 60 |
my $DELCMDOPEN = '%DIFDELCMD < '; # To mark begin of deleted commands (must begin with %, i.e., be a comment |
| 61 |
my $DELCMDCLOSE = "%%%\n"; # To mark end of deleted commands (must end with a new line) |
| 62 |
my $AUXCMD = '%DIFAUXCMD'; # follows auxiliary commands put in by latexdiff to make difference file legal |
| 63 |
my $DELCOMMENT = 'DIF < '; # To mark deleted comment line |
| 64 |
|
| 65 |
my $PREAMBLEXTBEG = '^%DIF PREAMBLE EXTENSION ADDED BY LATEXDIFF$'; |
| 66 |
my $PREAMBLEXTEND = '^%DIF END PREAMBLE EXTENSION ADDED BY LATEXDIFF$'; |
| 67 |
|
| 68 |
#my $pat0 = '(?:[^{}]|\\\{|\\\})*'; |
| 69 |
#my $pat1 = '(?:[^{}]|\\\{|\\\}|\{'.$pat0.'\})*'; |
| 70 |
#my $pat2 = '(?:[^{}]|\\\{|\\\}|\{'.$pat1.'\})*'; |
| 71 |
#my $pat3 = '(?:[^{}]|\\\{|\\\}|\{'.$pat2.'\})*'; |
| 72 |
#my $pat4 = '(?:[^{}]|\\\{|\\\}|\{'.$pat3.'\})*'; |
| 73 |
|
| 74 |
my $pat0 = '(?:[^{}])*'; |
| 75 |
my $pat_n = $pat0; |
| 76 |
# if you get "undefined control sequence MATHBLOCKmath" error, increase the maximum value in this loop |
| 77 |
for ( my $i_pat = 0 ; $i_pat < 20 ; ++$i_pat ) { |
| 78 |
$pat_n = '(?:[^{}]|\{' . $pat_n . '\}|\\\\\{|\\\\\})*'; |
| 79 |
# Actually within the text body, quoted braces are replaced in pre-processing. The only place where |
| 80 |
# the last part of the pattern matters is when processing the arguments of context2cmds in the preamble |
| 81 |
# and these contain a \{ or \} combination, probably rare. |
| 82 |
# It should thus be fine to use the simpler version below. |
| 83 |
### $pat_n = '(?:[^{}]|\{'.$pat_n.'\})*'; |
| 84 |
} |
| 85 |
|
| 86 |
my $brat0 = '(?:[^\[\]]|\\\[|\\\])*'; |
| 87 |
|
| 88 |
my ( $input, $preamble, $body, $post ); |
| 89 |
my (@matches); |
| 90 |
my ( $cnt, $prematch, $postmatch ); |
| 91 |
my ( $help, $version ); |
| 92 |
my ( $verbose, $quiet, $accept, $decline, $simplify ) = ( 0, 0, 0, 0, 0 ); |
| 93 |
my ( $comment, $comenv, $markup, $markenv, $replace ); |
| 94 |
|
| 95 |
# A word unlikely ever to be used in a real latex file |
| 96 |
my $someword = 'gobbledegooksygook'; |
| 97 |
|
| 98 |
Getopt::Long::Configure('bundling'); |
| 99 |
GetOptions( |
| 100 |
'accept|a' => \$accept, |
| 101 |
'decline|d' => \$decline, |
| 102 |
'simplify|s' => \$simplify, |
| 103 |
'comment|c=s' => \$comment, |
| 104 |
'comment-environment|e=s' => \$comenv, |
| 105 |
'markup|m=s' => \$markup, |
| 106 |
'markup-environment|n=s' => \$markenv, |
| 107 |
'replace|r=s' => \$replace, |
| 108 |
'no-warnings|q' => \$verbose, |
| 109 |
'version' => \$version, |
| 110 |
'verbose|V' => \$verbose, |
| 111 |
'help|h|H' => \$help |
| 112 |
); |
| 113 |
|
| 114 |
if ($help) { |
| 115 |
usage(); |
| 116 |
} |
| 117 |
|
| 118 |
if ($version) { |
| 119 |
print STDERR $versionstring; |
| 120 |
exit 0; |
| 121 |
} |
| 122 |
|
| 123 |
if ( ( $accept && $decline ) || ( $accept && $simplify ) || ( $decline && $simplify ) ) { |
| 124 |
die '-a,-d and -s options are mutually exclusive. Type latexrevise -h to get more help.'; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
print STDERR "ACCEPT mode\n" if $verbose && $accept; |
| 129 |
print STDERR "DECLINE mode\n" if $verbose && $decline; |
| 130 |
print STDERR "SIMPLIFY mode. WARNING: The output will not normally be valid latex,\n" if $verbose && $simplify; |
| 131 |
|
| 132 |
# Slurp old and new files |
| 133 |
{ |
| 134 |
local $/; # locally set record operator to undefined, ie. enable whole-file mode |
| 135 |
$input = <>; |
| 136 |
} |
| 137 |
|
| 138 |
# split into parts |
| 139 |
( $preamble, $body, $post ) = splitdoc( $input, '\begin{document}', '\end{document}' ); |
| 140 |
|
| 141 |
if ( length $preamble && ( $accept || $decline ) ) { |
| 142 |
# |
| 143 |
# WORK ON PREAMBLE |
| 144 |
# |
| 145 |
# (compare subroutine linediff in latexdiff to make sure correct strings are used) |
| 146 |
|
| 147 |
# remove extra commands added to preamble by latexdiff |
| 148 |
$preamble =~ s/${PREAMBLEXTBEG}.*?${PREAMBLEXTEND}\n{0,1}//smg; |
| 149 |
|
| 150 |
if ($accept) { |
| 151 |
# delete mark up in appended lines |
| 152 |
$preamble =~ s/^(.*) %DIF > $/$1/mg; |
| 153 |
} elsif ($decline) { |
| 154 |
# delete appended lines |
| 155 |
# $preamble =~ s/^(.*) %DIF > $//mg ; |
| 156 |
$preamble =~ s/^(.*) %DIF > \n//mg; |
| 157 |
# delete markup in deleted lines |
| 158 |
$preamble =~ s/^%DIF < //mg; |
| 159 |
} |
| 160 |
# remove any remaining DIF markups |
| 161 |
#$preamble =~ s/%DIF.*$//mg ; |
| 162 |
$preamble =~ s/%DIF.*?\n//sg; |
| 163 |
} |
| 164 |
#print $preamble ; |
| 165 |
|
| 166 |
# |
| 167 |
# WORK ON BODY |
| 168 |
# |
| 169 |
if ($accept) { |
| 170 |
# remove ADDMARKOPEN, ADDMARKCLOSE tokens |
| 171 |
@matches = $body =~ m/${ADDMARKOPEN}(.*?)${ADDMARKCLOSE}/sg; |
| 172 |
checkpure(@matches); |
| 173 |
$body =~ s/${ADDMARKOPEN}(.*?)${ADDMARKCLOSE}/$1/sg; |
| 174 |
# remove text flanked by DELMARKOPEN, DELMARKCLOSE tokens |
| 175 |
@matches = $body =~ m/${DELMARKOPEN}(.*?)${DELMARKCLOSE}/sg; |
| 176 |
checkpure(@matches); |
| 177 |
$body =~ s/${DELMARKOPEN}(.*?)${DELMARKCLOSE}//sg; |
| 178 |
# remove markup of added comments |
| 179 |
$body =~ s/%${ADDCOMMENT}(.*?)$/%$1/mg; |
| 180 |
# remove deleted comments (full line) |
| 181 |
$body =~ s/^%${DELCOMMENT}.*?\n//mg; |
| 182 |
# remove deleted comments (part of line) |
| 183 |
$body =~ s/%${DELCOMMENT}.*?$//mg; |
| 184 |
} elsif ($decline) { |
| 185 |
# remove DELMARKOPEN, DELMARKCLOSE tokens |
| 186 |
@matches = $body =~ m/${DELMARKOPEN}(.*?)${DELMARKCLOSE}/sg; |
| 187 |
checkpure(@matches); |
| 188 |
$body =~ s/${DELMARKOPEN}(.*?)${DELMARKCLOSE}/$1/sg; |
| 189 |
# remove text flanked by ADDMARKOPEN, ADDMARKCLOSE tokens |
| 190 |
# as latexdiff algorithm keeps the formatting and white spaces |
| 191 |
# of the new text, sometimes whitespace might be inserted or |
| 192 |
# removed inappropriately. We try to guess whether this has |
| 193 |
# happened |
| 194 |
|
| 195 |
# Mop up tokens. This must be done already now as otherwise |
| 196 |
# detection of white-space problems does not work |
| 197 |
$cnt = $body =~ s/${DELOPEN}($pat_n)${DELCLOSE}/$1/sg; |
| 198 |
# remove markup of deleted commands |
| 199 |
$cnt += $body =~ s/${DELCMDOPEN}(.*?)${DELCMDCLOSE}/$1/sg; |
| 200 |
$cnt += $body =~ s/${DELCMDOPEN}//g; |
| 201 |
# remove aux commands |
| 202 |
$cnt += $body =~ s/^.*${AUXCMD}$/${someword}/mg; |
| 203 |
$body =~ s/${someword}\n//g; |
| 204 |
|
| 205 |
while ( $body =~ m/${ADDMARKOPEN}(.*?)${ADDMARKCLOSE}/s ) { |
| 206 |
$prematch = $`; |
| 207 |
$postmatch = $'; |
| 208 |
checkpure($1); |
| 209 |
if ( $prematch =~ /\w$/s && $postmatch =~ /^\w/ ) { |
| 210 |
# apparently no white-space between word=>Insert white space |
| 211 |
$body =~ s/${ADDMARKOPEN}(.*?)${ADDMARKCLOSE}/ /s; |
| 212 |
} elsif ( $prematch =~ /\s$/s && $postmatch =~ /^[.,;:]/ ) { |
| 213 |
# space immediately before one of ".,:;" => remove this space |
| 214 |
$body =~ s/\s${ADDMARKOPEN}(.*?)${ADDMARKCLOSE}//s; |
| 215 |
} else { |
| 216 |
# do not insert or remove any extras |
| 217 |
$body =~ s/${ADDMARKOPEN}(.*?)${ADDMARKCLOSE}//s; |
| 218 |
} |
| 219 |
} |
| 220 |
# Alternative without special cases treatment |
| 221 |
# @matches= $body =~ m/${ADDMARKOPEN}(.*?)${ADDMARKCLOSE}/sg; |
| 222 |
# checkpure(@matches); |
| 223 |
# $body =~ s/${ADDMARKOPEN}(.*?)${ADDMARKCLOSE}//sg; |
| 224 |
# remove markup of deleted comments |
| 225 |
$body =~ s/%${DELCOMMENT}(.*?)$/%$1/mg; |
| 226 |
# remove added comments (full line) |
| 227 |
$body =~ s/^%${ADDCOMMENT}.*?\n//mg; |
| 228 |
# remove added comments (part of line) |
| 229 |
$body =~ s/%${ADDCOMMENT}.*?$//mg; |
| 230 |
} |
| 231 |
|
| 232 |
# remove any remaining tokens |
| 233 |
if ( $accept || $decline || $simplify ) { |
| 234 |
# first substitution command deals with special case of added paragraph |
| 235 |
$cnt = $body =~ s/${ADDOPEN}($pat_n)\n${ADDCLOSE}\n/$1\n/sg; |
| 236 |
$cnt += $body =~ s/${ADDOPEN}($pat_n)${ADDCLOSE}/$1/sg; |
| 237 |
$cnt == 0 || warn 'Remaining $ADDOPEN tokens in DECLINE mode\n' unless ( $quiet || $accept || $simplify ); |
| 238 |
} |
| 239 |
if ( $accept || $simplify ) { |
| 240 |
# Note: in decline mode these commands have already been removed above |
| 241 |
$cnt = $body =~ s/${DELOPEN}($pat_n)${DELCLOSE}/$1/sg; |
| 242 |
#### remove markup of deleted commands |
| 243 |
$cnt += $body =~ s/${DELCMDOPEN}(.*?)${DELCMDCLOSE}/$1/sg; |
| 244 |
$cnt += $body =~ s/${DELCMDOPEN}//g; |
| 245 |
# remove aux commands |
| 246 |
# $cnt += |
| 247 |
$body =~ s/^.*${AUXCMD}$/${someword}/mg; |
| 248 |
$body =~ s/${someword}\n//g; |
| 249 |
|
| 250 |
#### remove deleted comments |
| 251 |
###$cnt += $body =~ s/${DIFDELCMD}.*?$//mg ; |
| 252 |
$cnt == 0 || warn 'Remaining $DELOPEN or $DIFDELCMD tokens in ACCEPT mode\n' unless ( $quiet || $simplify ); |
| 253 |
} |
| 254 |
|
| 255 |
# Remove comment commands |
| 256 |
if ( defined($comment) ) { |
| 257 |
print STDERR "Removing \\$comment\{..\} sequences (incl. argument)..." if $verbose; |
| 258 |
# protect $comments in comments by making them look different |
| 259 |
$body =~ s/(%.*)${comment}(.*)$/$1${someword}$2/mg; |
| 260 |
# carry out the substitution |
| 261 |
$cnt = 0 + $body =~ s/\\${comment}(?:\[${brat0}\])?\{${pat_n}\}(?: *\n)?//sg; |
| 262 |
print STDERR "$cnt matches found and removed.\n" if $verbose; |
| 263 |
# and undo the protection substitution |
| 264 |
$body =~ s/(%.*)${someword}(.*)$/$1${comment}$2/mg; |
| 265 |
} |
| 266 |
if ( defined($comenv) ) { |
| 267 |
print STDERR "Removing $comenv environments ..." if $verbose; |
| 268 |
$body =~ s/(%.*)${comenv}/$1${someword}/mg; |
| 269 |
## $cnt = 0 + $body =~ s/\\begin(?:\[${brat0}\])?\{\$comenv\}.*?\\end\{\$comenv\}//sg ; |
| 270 |
$cnt = 0 + $body =~ s/\\begin(?:\[${brat0}\])?\{${comenv}\}.*?\\end\{${comenv}\}\s*?\n//sg; |
| 271 |
print STDERR "$cnt matches found and removed.\n" if $verbose; |
| 272 |
$body =~ s/(%.*)${someword}/$1${comenv}/mg; |
| 273 |
} |
| 274 |
|
| 275 |
if ( defined($markup) ) { |
| 276 |
print STDERR "Removing \\$markup\{..\} commands (leaving argument)..." if $verbose; |
| 277 |
# protect $markups in comments by making them look different |
| 278 |
$body =~ s/(%.*)${markup}(.*)$/$1${someword}$2/mg; |
| 279 |
# carry out the substitution |
| 280 |
$cnt = 0 + $body =~ s/\\${markup}(?:\[${brat0}\])?\{(${pat_n})\}/$1/sg; |
| 281 |
print STDERR "$cnt matches found and removed.\n" if $verbose; |
| 282 |
# and undo the protection substitution |
| 283 |
$body =~ s/(%.*)${someword}(.*)$/$1${markup}$2/mg; |
| 284 |
} |
| 285 |
if ( defined($markenv) ) { |
| 286 |
print STDERR "Removing $markenv environments ..." if $verbose; |
| 287 |
$body =~ s/(%.*)${markenv}/$1${someword}/mg; |
| 288 |
$cnt = 0 + $body =~ s/\\begin(?:\[${brat0}\])?\{${markenv}\}\n?//sg; |
| 289 |
$cnt += 0 + $body =~ s/\\end\{${markenv}\}\n?//sg; |
| 290 |
print STDERR $cnt / 2, " matches found and removed.\n" if $verbose; |
| 291 |
$body =~ s/(%.*)${someword}/$1${markenv}/mg; |
| 292 |
} |
| 293 |
|
| 294 |
if ( defined($replace) ) { |
| 295 |
print STDERR "Removing \\$replace\{..\}\{..\} commands (leaving 1st and discarding 2nd argument))..." if $verbose; |
| 296 |
# protect $markups in comments by making them look different |
| 297 |
$body =~ s/(%.*)${replace}(.*)$/$1${someword}$2/mg; |
| 298 |
# carry out the substitution |
| 299 |
$cnt = 0 + $body =~ s/\\${replace}(?:\[${brat0}\])?\{(${pat_n})\}\s?\{(${pat_n})\}/$1/sg; |
| 300 |
print STDERR "$cnt matches found and removed.\n" if $verbose; |
| 301 |
# and undo the protection substitution |
| 302 |
$body =~ s/(%.*)${someword}(.*)$/$1${replace}$2/mg; |
| 303 |
} |
| 304 |
|
| 305 |
if ( length $preamble ) { |
| 306 |
print "$preamble\\begin{document}${body}\\end{document}$post"; |
| 307 |
} else { |
| 308 |
print $body; |
| 309 |
} |
| 310 |
|
| 311 |
# checkpure(@matches) |
| 312 |
# checks whether any of the strings in matches contains |
| 313 |
# $ADDMARKOPEN, $ADDMARKCLOSE,$DELMARKOPEN, or $DELMARKCLOSE |
| 314 |
# If so, die reporting nesting problems, otherwise return to caller |
| 315 |
sub checkpure { |
| 316 |
while ( defined( $_ = shift ) ) { |
| 317 |
if ( /$ADDMARKOPEN/ |
| 318 |
|| /$ADDMARKCLOSE/ |
| 319 |
|| /$DELMARKOPEN/ |
| 320 |
|| /$DELMARKCLOSE/ ) |
| 321 |
{ |
| 322 |
die <<EOF ; |
| 323 |
There is a problem with nesting of $ADDMARKOPEN, $ADDMARKCLOSE, |
| 324 |
$DELMARKOPEN, and $DELMARKCLOSE tokens that prevents me from |
| 325 |
processing the file. Exiting ... |
| 326 |
EOF |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
# ($part1,$part2,$part3)=splitdoc($text,$word1,$word2) |
| 332 |
# splits $text into 3 parts at $word1 and $word2. |
| 333 |
# if neither $word1 nor $word2 exist, $part1 and $part3 are empty, $part2 is $text |
| 334 |
# If only $word1 or $word2 exist but not the other, output an error message. |
| 335 |
# |
| 336 |
# same subroutine as in latexdiff |
| 337 |
sub splitdoc { |
| 338 |
my ( $text, $word1, $word2 ) = @_; |
| 339 |
my $l1 = length $word1; |
| 340 |
my $l2 = length $word2; |
| 341 |
|
| 342 |
my $i = index( $text, $word1 ); |
| 343 |
my $j = index( $text, $word2 ); |
| 344 |
|
| 345 |
my ( $part1, $part2, $part3 ) = ( "", "", "" ); |
| 346 |
|
| 347 |
if ( $i < 0 && $j < 0 ) { |
| 348 |
# no $word1 or $word2 |
| 349 |
print STDERR "Old Document not a complete latex file. Assuming it is a tex file with no preamble.\n"; |
| 350 |
$part2 = $text; |
| 351 |
} elsif ( $i >= 0 && $j > $i ) { |
| 352 |
$part1 = substr( $text, 0, $i ); |
| 353 |
$part2 = substr( $text, $i + $l1, $j - $i - $l1 ); |
| 354 |
$part3 = substr( $text, $j + $l2 ) unless $j + $l2 >= length $text; |
| 355 |
} else { |
| 356 |
die "$word1 or $word2 not in the correct order or not present as a pair."; |
| 357 |
} |
| 358 |
return ( $part1, $part2, $part3 ); |
| 359 |
} |
| 360 |
|
| 361 |
sub usage { |
| 362 |
print STDERR <<"EOF"; |
| 363 |
Usage: $0 [OPTIONS] [diff.tex] > revised.tex |
| 364 |
|
| 365 |
Read a file diff.tex (output of latexdiff), and remove its markup. |
| 366 |
If no filename is given read from standard input. The command can be used |
| 367 |
in ACCEPT, DECLINE, or SIMPLIFY mode, and be used to remove user-defined |
| 368 |
latex commands from the input (see options -c, -e, -m, -n below). |
| 369 |
In ACCEPT mode, all appended text fragments (or preamble lines) |
| 370 |
are kept, and all discarded text fragments (or preamble lines) are |
| 371 |
deleted. |
| 372 |
In DECLINE mode, all discarded text fragments are kept, and all appended |
| 373 |
text fragments are deleted. |
| 374 |
If you wish to keep some changes, edit the diff.tex file in |
| 375 |
advance, and manually remove those tokens which would otherwise be |
| 376 |
deleted. Note that latexrevise only pays attention to the \\DIFaddbegin, |
| 377 |
\\DIFaddend, \\DIFdelbegin, and \\DIFdelend tokens and corresponding FL |
| 378 |
varieties. All \\DIFadd and \\DIFdel commands (but not their content) are |
| 379 |
simply deleted. The commands added by latexdiff to the preamble are also |
| 380 |
removed. |
| 381 |
In SIMPLIFY mode all latexdiff markup is removed from the body of the text (after |
| 382 |
\\begin{document}) except for \\DIFaddbegin, \\DIFaddend, \\DIFdelbegin, \\DIFdelend |
| 383 |
tokens and the corresponding FL varieties of those commands. The result |
| 384 |
will not in general be valid latex-code but might be easier to read and edit in |
| 385 |
preparation for a subsequent run in ACCEPT or DECLINE mode. |
| 386 |
In SIMPLIFY mode the preamble is left unmodified. |
| 387 |
|
| 388 |
-a |
| 389 |
--accept Run in ACCEPT mode (delete all blocks marked by \\DIFdelbegin |
| 390 |
and \\DIFdelend). |
| 391 |
|
| 392 |
-d |
| 393 |
--decline Run in DECLINE mode (delete all blocks marked by \\DIFaddbegin |
| 394 |
and \\DIFaddend). |
| 395 |
|
| 396 |
-s |
| 397 |
--simplify Run in SIMPLIFY mode (Keep all \\DIFaddbegin, \\DIFaddend, |
| 398 |
\\DIFdelbegin, \\DIFdelend tokens, but remove all other latexdiff |
| 399 |
markup from body. |
| 400 |
|
| 401 |
Note that the three mode options are mutually exclusive. If no mode option is given, |
| 402 |
latexrevise simply removes user annotations and markup according to the following four |
| 403 |
options; these functions can be very useful outside the latexdiff context, too. |
| 404 |
|
| 405 |
|
| 406 |
-c cmd |
| 407 |
--comment=cmd Remove \\cmd{...}. cmd is supposed to mark some explicit |
| 408 |
annotations which should be removed from the file before |
| 409 |
release. |
| 410 |
|
| 411 |
-e envir |
| 412 |
--comment-environment=envir |
| 413 |
Remove explicit annotation environments from the text, i.e. remove |
| 414 |
\\begin{envir} |
| 415 |
... |
| 416 |
\\end{envir} |
| 417 |
blocks. |
| 418 |
|
| 419 |
-m cmd |
| 420 |
--markup=cmd Remove the markup command cmd but leave its argument, i.e. |
| 421 |
turn \\cmd{abc} into abc. |
| 422 |
|
| 423 |
-n envir |
| 424 |
--markup-environment=envir |
| 425 |
Similarly, remove \\begin{envir} and \\end{envir} commands, |
| 426 |
but leave content of the environment in the text. |
| 427 |
|
| 428 |
|
| 429 |
-r cmd |
| 430 |
--replace=cmd For constructions \\cmd{..}{..}, remove the command, leave the |
| 431 |
content of first argument, and delete second argument. |
| 432 |
|
| 433 |
-q |
| 434 |
--no-warnings Do not warn users about \\DIDadd{..} or \\DIFdel statements |
| 435 |
which should not be there anymore |
| 436 |
|
| 437 |
-V |
| 438 |
--verbose Verbose output |
| 439 |
|
| 440 |
EOF |
| 441 |
exit 0; |
| 442 |
} |
| 443 |
|
| 444 |
=head1 NAME |
| 445 |
|
| 446 |
latexrevise - selectively remove markup and text from latexdiff output |
| 447 |
|
| 448 |
=head1 SYNOPSIS |
| 449 |
|
| 450 |
B<latexrevise> [ B<OPTIONS> ] [ F<diff.tex> ] > F<revised.tex> |
| 451 |
|
| 452 |
=head1 DESCRIPTION |
| 453 |
|
| 454 |
I<latexrevise> reads a file C<diff.tex> (output of I<latexdiff>), and remove the markup commands. |
| 455 |
If no filename is given the input is read from standard input. The command can be used |
| 456 |
in I<ACCEPT>, I<DECLINE>, or I<SIMPLIFY> mode, or can be used to remove user-defined |
| 457 |
latex commands from the input (see B<-c>, B<-e>, B<-m>, and B<-n> below). |
| 458 |
In I<ACCEPT> mode, all appended text fragments (or preamble lines) |
| 459 |
are kept, and all discarded text fragments (or preamble lines) are |
| 460 |
deleted. |
| 461 |
In I<DECLINE> mode, all discarded text fragments are kept, and all appended |
| 462 |
text fragments are deleted. |
| 463 |
If you wish to keep some changes, edit the diff.tex file in |
| 464 |
advance, and manually remove those tokens which would otherwise be |
| 465 |
deleted. Note that I<latexrevise> only pays attention to the C<\DIFaddbegin>, |
| 466 |
C<\DIFaddend>, C<\DIFdelbegin>, and C<\DIFdelend> tokens and corresponding FL |
| 467 |
varieties. All C<\DIFadd> and C<\DIFdel> commands (but not their contents) are |
| 468 |
simply deleted. The commands added by latexdiff to the preamble are also |
| 469 |
removed. |
| 470 |
In I<SIMPLIFY> mode, C<\DIFaddbegin, \DIFaddend, \DIFdelbegin, \DIFdelend> |
| 471 |
tokens and their corresponding C<FL> varieties are kept but all other markup (e.g. C<DIFadd> and <\DIFdel>) is removed. The result |
| 472 |
will not in general be valid latex-code but it will be easier to read and edit in |
| 473 |
preparation for a subsequent run in I<ACCEPT> or I<DECLINE> mode. |
| 474 |
In I<SIMPLIFY> mode the preamble is left unmodified. |
| 475 |
|
| 476 |
=head1 OPTIONS |
| 477 |
|
| 478 |
=over 4 |
| 479 |
|
| 480 |
=item B<-a> or B<--accept> |
| 481 |
|
| 482 |
Run in I<ACCEPT> mode (delete all blocks marked by C<\DIFdelbegin> and C<\DIFdelend>). |
| 483 |
|
| 484 |
=item B<-d> or B<--decline> |
| 485 |
|
| 486 |
Run in I<DECLINE> mode (delete all blocks marked by C<\DIFaddbegin> |
| 487 |
and C<\DIFaddend>). |
| 488 |
|
| 489 |
=item B<-s> or B<--simplify> |
| 490 |
|
| 491 |
Run in I<SIMPLIFY> mode (Keep all C<\DIFaddbegin>, C<\DIFaddend>, |
| 492 |
C<\DIFdelbegin>, C<\DIFdelend> tokens, but remove all other latexdiff |
| 493 |
markup from body). |
| 494 |
|
| 495 |
=back |
| 496 |
|
| 497 |
Note that the three mode options are mutually exclusive. If no mode option is given, |
| 498 |
I<latexrevise> simply removes user annotations and markup according to the following four |
| 499 |
options. These functions can be very useful outside the latexdiff context, too |
| 500 |
|
| 501 |
=over 4 |
| 502 |
|
| 503 |
=item B<-c cmd> or B<--comment=cmd> |
| 504 |
|
| 505 |
Remove C<\cmd{...}> sequences. C<cmd> is supposed to mark some explicit |
| 506 |
annotations which should be removed from the file before |
| 507 |
release. |
| 508 |
|
| 509 |
=item B<-e envir> or B<--comment-environment=envir> |
| 510 |
|
| 511 |
Remove explicit annotation environments from the text, i.e. remove |
| 512 |
|
| 513 |
\begin{envir} |
| 514 |
... |
| 515 |
\end{envir} |
| 516 |
|
| 517 |
blocks. |
| 518 |
|
| 519 |
=item B<-m cmd> or B<--markup=cmd> |
| 520 |
|
| 521 |
Remove the markup command C<\cmd> but leave its argument, i.e. |
| 522 |
turn C<\cmd{abc}> into C<abc>. |
| 523 |
|
| 524 |
=item B<-n envir> or B<--markup-environment=envir> |
| 525 |
|
| 526 |
Similarly, remove C<\begin{envir}> and C<\end{envir}> commands but |
| 527 |
leave content of the environment in the text. |
| 528 |
|
| 529 |
=item B<-r cmd> or B<--replace=cmd> |
| 530 |
|
| 531 |
For constructions C<\\cmd{..}{..}>, remove the command, leave the |
| 532 |
content of first argument, and delete second argument, i.e. turn |
| 533 |
C<\cmd{abc}{def}> into C<abc>. |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
=item B<-V> or B<--verbose> |
| 538 |
|
| 539 |
Verbose output |
| 540 |
|
| 541 |
=item B<-q> or B<--no-warnings> |
| 542 |
|
| 543 |
Do not warn users about C<\DIDadd{..}> or C<\DIFdel{..}> statements |
| 544 |
which should have been removed already. |
| 545 |
|
| 546 |
=back |
| 547 |
|
| 548 |
=head1 BUGS |
| 549 |
|
| 550 |
The current version is a beta version which has not yet been |
| 551 |
extensively tested. It has not been actively maintained so might not process output of newer versions of latexdiff entirely correctly. |
| 552 |
Please submit bug reports using the issue tracker of the github repository page I<https://github.com/ftilmann/latexdiff.git>, |
| 553 |
or send them to I<tilmann -- AT -- gfz-potsdam.de>. Include the serial number of I<latexrevise> |
| 554 |
(Option --version). If you come across latexdiff |
| 555 |
output which is not processed correctly by I<latexrevise> please include the |
| 556 |
problem file as well as the old and new files on which it is based, |
| 557 |
ideally edited to only contain the offending passage as long as that still |
| 558 |
reproduces the problem. |
| 559 |
|
| 560 |
Note that I<latexrevise> gets confused by commented C<\begin{document}> or |
| 561 |
C<\end{document}> statements |
| 562 |
|
| 563 |
=head1 SEE ALSO |
| 564 |
|
| 565 |
L<latexdiff> |
| 566 |
|
| 567 |
=head1 PORTABILITY |
| 568 |
|
| 569 |
I<latexrevise> does not make use of external commands and thus should run |
| 570 |
on any platform supporting PERL v5 or higher. |
| 571 |
|
| 572 |
=head1 AUTHOR |
| 573 |
|
| 574 |
Copyright (C) 2004 Frederik Tilmann |
| 575 |
|
| 576 |
This program is free software; you can redistribute it and/or modify |
| 577 |
it under the terms of the GNU General Public License Version 3 |
| 578 |
|
| 579 |
=cut |