summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xBuild/source/texk/texlive/linked_scripts/ltximg/ltximg.pl1253
-rwxr-xr-xBuild/source/texk/texlive/linked_scripts/texlive/tlmgr.pl36
-rw-r--r--Master/texmf-dist/doc/support/ltximg/CHANGES7
-rw-r--r--Master/texmf-dist/doc/support/ltximg/README64
-rw-r--r--Master/texmf-dist/doc/support/ltximg/ltximg-doc.pdfbin51940 -> 346033 bytes
-rw-r--r--Master/texmf-dist/doc/support/ltximg/ltximg-doc.tex427
-rw-r--r--Master/texmf-dist/doc/support/ltximg/test.tex47
-rwxr-xr-xMaster/texmf-dist/scripts/ltximg/ltximg.pl1253
8 files changed, 2083 insertions, 1004 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/ltximg/ltximg.pl b/Build/source/texk/texlive/linked_scripts/ltximg/ltximg.pl
index ccb7f92fe2d..d9aefa8164a 100755
--- a/Build/source/texk/texlive/linked_scripts/ltximg/ltximg.pl
+++ b/Build/source/texk/texlive/linked_scripts/ltximg/ltximg.pl
@@ -1,40 +1,243 @@
-#!/usr/bin/perl
-use v5.14;
-use strict; # to be sure, that all is safe ... :-)
-use File::Path;
-use File::Copy;
-use File::Basename;
-use IO::File;
-use Getopt::Long;
-use autodie;
-
-my $tempDir = "."; # temporary directory
-my $clear = 0; # 0 or 1, clears all temporary files
-my $DPI = "300"; # value for ppm
-my $margins = "0"; # margins for pdf crop
-my $imageDir = "images"; # directorio de imágenes (images por defecto)
-my $skip = "skip"; # skip environment
-my $latex = 0; # 1->create all images using latex
-my $xetex = 0; # 1->create all images using xelatex
-my $luatex = 0; # 1->create all images using lualatex
-my $IMO = ""; # 1->Options for ImageMagick
-my $GSCMD = "gs"; # Ghostscript name
-my $other = "other"; # search other environment for export
-my $pdf = 0; # 1->create .pdf using ghostscript
-my $png = 0; # 1->create .png
-my $jpg = 0; # 1->create .jpg
-my $eps = 0; # 1->create .eps using pdftops
-my $ppm = 0; # 1->create .ppm using pdftoppm
-my $useppm = 0; # 1->create jpg/png using mogrify and ppm
-my $usemog = 0; # 1->create jpg/png using mogrify
-my $all = 0; # 1->create all images and files for type
-
-#----------------------- User part end ---------------------------
-#-----------------program identification, options and help--------
-my $program = "ltximg";
-my $ident = '$Id: ltximg v1.0, 2013-03-12 pablo $';
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' if 0;
+use v5.18;
+use File::Path; # creating/removing dirs
+use File::Copy; # copying files
+use File::Basename; # scan argument
+use IO::File; # simple IO operation
+use Getopt::Long qw(:config bundling_override); # read parameter and activate "bundling"
+use autodie; # more safe
+use Config;
+use File::Spec;
+use File::Find;
+
+#------------------------ Constantes ----------------------------------#
+my $tempDir = "."; # temporary directory
+my $other = "other"; # other environment for search
+my $imageDir = "images"; # Dir for images (images default)
+my $ignore = "ignore"; # ignore verbatim environment
+my $exacount = 1; # Counter for source images
+my $imgNo = 1; # Counter for PGF/TIKZ/PST environments
+my $nopreview = 0; # 1->create images in nopreview mode
+my $noSource = 0; # Delete TeX source for images
+my $nopdf = 0; # No create a PDF image file
+my $clear = 0; # 0 or 1, clears all temporary files
+my $DPI = "150"; # value for ppm, png, jpg
+my $margins = "0"; # margins for pdf crop
+my $latex = 0; # 1->create all images using latex
+my $xetex = 0; # 1->create all images using xelatex
+my $luatex = 0; # 1->create all images using lualatex
+my $png = 0; # 1->create .png using Ghoscript
+my $jpg = 0; # 1->create .jpg using Ghoscript
+my $eps = 0; # 1->create .eps using pdftops
+my $svg = 0; # 1->create .svg files
+my $ppm = 0; # 1->create .ppm using pdftoppm
+my $all = 0; # 1->create all images and files for type
+my $output = 0; # 1->create output file whitout PGF/PST
+my $miktex = 0; # 1->enable write 18 for miktex system
+my $Verbose = 0; # 0 or 1, logfile
+
+#------------------------------ CHANGES -------------------------------#
+# v1.2 2015-04-21 - Change mogrify to gs for image formats
+# - Create output file
+# - Rewrite source code and fix regex
+# - Add more image format
+# - Change date to iso format
+# v1.0 2013-12-01 - First public release
+#----------------------------------------------------------------------#
+
+#----------------------------- Search GS ------------------------------#
+# The next code its part of pdfcrop from TexLive 2014
+# Windows detection
+my $Win = 0;
+$Win = 1 if $^O =~ /mswin32/i;
+$Win = 1 if $^O =~ /cygwin/i;
+
+my $archname = $Config{'archname'};
+$archname = 'unknown' unless defined $Config{'archname'};
+
+# get Ghostscript command name
+$::opt_gscmd = '';
+sub find_ghostscript () {
+ return if $::opt_gscmd;
+ if ($Verbose) {
+ print "* Perl executable: $^X\n";
+ if ($] < 5.006) {
+ print "* Perl version: $]\n";
+ }
+ else {
+ printf "* Perl version: v%vd\n", $^V;
+ }
+ if (defined &ActivePerl::BUILD) {
+ printf "* Perl product: ActivePerl, build %s\n", ActivePerl::BUILD();
+ }
+ printf "* Pointer size: $Config{'ptrsize'}\n";
+ printf "* Pipe support: %s\n",
+ (defined($Config{'d_pipe'}) ? 'yes' : 'no');
+ printf "* Fork support: %s\n",
+ (defined($Config{'d_fork'}) ? 'yes' : 'no');
+ }
+ my $system = 'unix';
+ $system = "dos" if $^O =~ /dos/i;
+ $system = "os2" if $^O =~ /os2/i;
+ $system = "win" if $^O =~ /mswin32/i;
+ $system = "cygwin" if $^O =~ /cygwin/i;
+ $system = "miktex" if defined($ENV{"TEXSYSTEM"}) and
+ $ENV{"TEXSYSTEM"} =~ /miktex/i;
+ print "* OS name: $^O\n" if $Verbose;
+ print "* Arch name: $archname\n" if $Verbose;
+ print "* System: $system\n" if $Verbose;
+ my %candidates = (
+ 'unix' => [qw|gs gsc|],
+ 'dos' => [qw|gs386 gs|],
+ 'os2' => [qw|gsos2 gs|],
+ 'win' => [qw|gswin32c gs|],
+ 'cygwin' => [qw|gs gswin32c|],
+ 'miktex' => [qw|mgs gswin32c gs|]
+ );
+ if ($system eq 'win' or $system eq 'cygwin' or $system eq 'miktex') {
+ if ($archname =~ /mswin32-x64/i) {
+ my @a = ();
+ foreach my $name (@{$candidates{$system}}) {
+ push @a, 'gswin64c' if $name eq 'gswin32c';
+ push @a, $name;
+ }
+ $candidates{$system} = \@a;
+ }
+ }
+ my %exe = (
+ 'unix' => '',
+ 'dos' => '.exe',
+ 'os2' => '.exe',
+ 'win' => '.exe',
+ 'cygwin' => '.exe',
+ 'miktex' => '.exe'
+ );
+ my $candidates_ref = $candidates{$system};
+ my $exe = $Config{'_exe'};
+ $exe = $exe{$system} unless defined $exe;
+ my @path = File::Spec->path();
+ my $found = 0;
+ foreach my $candidate (@$candidates_ref) {
+ foreach my $dir (@path) {
+ my $file = File::Spec->catfile($dir, "$candidate$exe");
+ if (-x $file) {
+ $::opt_gscmd = $candidate;
+ $found = 1;
+ print "* Found ($candidate): $file\n" if $Verbose;
+ last;
+ }
+ print "* Not found ($candidate): $file\n" if $Verbose;
+ }
+ last if $found;
+ }
+ if (not $found and $Win) {
+ $found = SearchRegistry();
+ }
+ if ($found) {
+ print "* Autodetected ghostscript command: $::opt_gscmd\n" if $Verbose;
+ }
+ else {
+ $::opt_gscmd = $$candidates_ref[0];
+ print "* Default ghostscript command: $::opt_gscmd\n" if $Verbose;
+ }
+}
+
+sub SearchRegistry () {
+ my $found = 0;
+ eval 'use Win32::TieRegistry qw|KEY_READ REG_SZ|;';
+ if ($@) {
+ if ($Verbose) {
+ print "* Registry lookup for Ghostscript failed:\n";
+ my $msg = $@;
+ $msg =~ s/\s+$//;
+ foreach (split /\r?\n/, $msg) {
+ print " $_\n";
+ }
+ }
+ return $found;
+ }
+ my $open_params = {Access => KEY_READ(), Delimiter => '/'};
+ my $key_name_software = 'HKEY_LOCAL_MACHINE/SOFTWARE/';
+ my $current_key = $key_name_software;
+ my $software = new Win32::TieRegistry $current_key, $open_params;
+ if (not $software) {
+ print "* Cannot find or access registry key `$current_key'!\n"
+ if $::opt_verbose;
+ return $found;
+ }
+ print "* Search registry at `$current_key'.\n" if $Verbose;
+ my %list;
+ foreach my $key_name_gs (grep /Ghostscript/i, $software->SubKeyNames()) {
+ $current_key = "$key_name_software$key_name_gs/";
+ print "* Registry entry found: $current_key\n" if $Verbose;
+ my $key_gs = $software->Open($key_name_gs, $open_params);
+ if (not $key_gs) {
+ print "* Cannot open registry key `$current_key'!\n" if $Verbose;
+ next;
+ }
+ foreach my $key_name_version ($key_gs->SubKeyNames()) {
+ $current_key = "$key_name_software$key_name_gs/$key_name_version/";
+ print "* Registry entry found: $current_key\n" if $Verbose;
+ if (not $key_name_version =~ /^(\d+)\.(\d+)$/) {
+ print " The sub key is not a version number!\n" if $Verbose;
+ next;
+ }
+ my $version_main = $1;
+ my $version_sub = $2;
+ $current_key = "$key_name_software$key_name_gs/$key_name_version/";
+ my $key_version = $key_gs->Open($key_name_version, $open_params);
+ if (not $key_version) {
+ print "* Cannot open registry key `$current_key'!\n" if $Verbose;
+ next;
+ }
+ $key_version->FixSzNulls(1);
+ my ($value, $type) = $key_version->GetValue('GS_DLL');
+ if ($value and $type == REG_SZ()) {
+ print " GS_DLL = $value\n" if $Verbose;
+ $value =~ s|([\\/])([^\\/]+\.dll)$|$1gswin32c.exe|i;
+ my $value64 = $value;
+ $value64 =~ s/gswin32c\.exe$/gswin64c.exe/;
+ if ($archname =~ /mswin32-x64/i and -f $value64) {
+ $value = $value64;
+ }
+ if (-f $value) {
+ print "EXE found: $value\n" if $Verbose;
+ }
+ else {
+ print "EXE not found!\n" if $Verbose;
+ next;
+ }
+ my $sortkey = sprintf '%02d.%03d %s',
+ $version_main, $version_sub, $key_name_gs;
+ $list{$sortkey} = $value;
+ }
+ else {
+ print "Missing key `GS_DLL' with type `REG_SZ'!\n" if $Verbose;
+ }
+ }
+ }
+ foreach my $entry (reverse sort keys %list) {
+ $::opt_gscmd = $list{$entry};
+ print "* Found (via registry): $::opt_gscmd\n" if $Verbose;
+ $found = 1;
+ last;
+ }
+ return $found;
+}
+
+find_ghostscript();
+
+if ($Win and $::opt_gscmd =~ /\s/) {
+ $::opt_gscmd = "\"$::opt_gscmd\"";
+}
+# end GS search
+
+#-----------------Program identification, options and help ------------#
+
+my $program = "LTXimg";
+my $nv='1.1';
my $copyright = <<END_COPYRIGHT ;
-Copyright 2013-01-12 (c) Pablo Gonzalez L <pablgonz\@yahoo.com>
+2015-04-21 - Copyright (c) 2013-2015 by Pablo Gonzalez L.
END_COPYRIGHT
my $licensetxt = <<END_LICENSE ;
This program is free software; you can redistribute it and/or modify
@@ -52,74 +255,86 @@ my $licensetxt = <<END_LICENSE ;
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
END_LICENSE
-my $title = "$program $ident\n";
+my $title = "$program $nv, $copyright";
my $usage = <<"END_OF_USAGE";
-${title}Usage: $program file.tex [options]
-ltximg create a copy for TeX source whit all TiKZ|Pstricks environments
- and convert all environments into single images (pdf/png/eps/jpg).
- By default search and extract TiKZ environments using (pdf)LaTeX
- and ghostscript (gs).
+${title}
+Usage: ltximg file.tex [options]
-Options:
+LTXimg extract and convert all PGF|TiKZ|Pstricks environments from TeX
+ source into single images files (pdf/png/eps/jpg/svg) using Ghostscript.
+ By default search and extract environments using (pdf)LaTeX.
+
+Environments suports by LTXimg:
- --h|help - display this help and exit
- --v|version - display version information and exit
- --li|license - display license information and exit
- --imageDir= - the dir for the created images (default images)
- --d|DPI= - dots per inch for gs, pdftoppm and mogrify (default 300)
- --IMO="..." - aditional options for mogrify (need double quotes)
- --c|clear - delete all temp files
- --xe|xetex - create all image using xelatex (tikz and pstricks)
- --lu|luatex - create all image using lualatex (tikz)
- --la|latex - create all image using latex (pstricks)
- --up|useppm - create jpg and png using mogrify and ppm
- --um|usemog - create jpg and png (transparent) using mogrify and pdf
- --m|margins= - margins for pdfcrop (default 0)
- --pdf - create .pdf files using gs
- --ppm - create .ppm files (need pdftoppm)
- --eps - create .eps files (need pdftops)
- --jpg - create .jpg files (deafult use gs)
- --png - create .png files (deafult use gs)
- --s|skip= - name for skip environmet in input file (default skip)
- --o|other= - name for other export environmet (default other)
- --a|all - create pdf/jpg/png/eps image type
+ pspicture tikzpicture pgfpicture forest ganttchart
+ tikzcd circuitikz dependency other postscript
+Options:
+
+ -h,--help - display this help and exit
+ -l,--license - display license information and exit
+ -v,--version - display version (current $nv) and exit
+ -d,--dpi=<int> - the dots per inch for images (default $DPI)
+ -j,--jpg - create .jpg files (need Ghostscript)
+ -p,--png - create .png files (need Ghostscript)
+ -e,--eps - create .eps files (need pdftops)
+ -s,--svg - create .svg files (need pdf2svg)
+ -P,--ppm - create .ppm files (need pdftoppm)
+ -a,--all - create .(pdf,eps,jpg,png) images
+ -c,--clear - delete all temp and aux files
+ -o,--output - create a file-out.tex whitout PGF|TiKZ|PST code
+ -m,--margins=<int> - margins in bp for pdfcrop (default 0)
+ -np,--nopreview - create images files whitout preview package
+ -ns,--nosource - delete all source for images files
+ --miktex - use --enable-write18 for MikTeX users
+ --xetex - using (Xe)LaTeX for create images
+ --latex - using LaTeX for create images
+ --luatex - using (Lua)LaTeX for create images
+ --nopdf - don't create a PDF image files (default off)
+ --other=<string> - search other environment (default other)
+ --ignore=<string> - skip verbatim environment (default ignore)
+ --imgdir=<string> - the folder for images (default images)
+
+
+
Example:
-* $program test.tex --xe -eps -jpg -c
-* produce test-fig-1.pdf, test-fig-2.pdf, test-fig-3.pdf,...
-* and test-fig-1.eps, test-fig-2.eps, test-fig-3.eps,... and
-* test-fig-1.jpg, test-fig-2.jpg, test-fig-3.jpg,... for all
-* TiKZ|Pst environments in image dir using gs and (Xe)latex.
+* ltximg test.tex -e -p -j -c -o --imgdir=pics
+* produce test-out.tex whitout PGF|TiKZ|PST environments and create "pics"
+* dir whit all images (pdf,eps,png,jpg) and source (.tex) for all related
+* parts using (pdf)LaTeX whit preview package and cleaning all tmp files.
+* Suport bundling for short options: ltximg test.tex -epjco --imgdir=pics
END_OF_USAGE
# Options
-my $result = GetOptions ("imageDir=s" => \$imageDir,
- "s|skip=s" => \$skip,
- 'h|help' => \$::opt_help,
- 'v|version' => \$::opt_version,
- 'li|license' => \$::opt_license,
- 'd|DPI=i' => \$DPI,
- "tempDir=s" => \$tempDir,
- 'c|clear' => \$clear,
- "la|latex" => \$latex,
- "xe|xetex" => \$xetex,
- "lu|luatex" => \$luatex,
- "o|other=s" => \$other,
- "m|margins=s" => \$margins,
- "GSCMD=s" => \$GSCMD,
- "IMO=s" => \$IMO,
- "png" => \$png,
- "jpg" => \$jpg,
- "eps" => \$eps,
- "ppm" => \$ppm,
- "up|useppm" => \$useppm,
- "um|usemog" => \$usemog,
- "pdf" => \$pdf,
- "a|all" => \$all
- ) or die $usage;
+my $result=GetOptions (
+ 'h|help' => \$::opt_help,
+ 'v|version' => \$::opt_version,
+ 'l|license' => \$::opt_license,
+ 'd|dpi=i' => \$DPI,# numeric
+ 'm|margins=i' => \$margins,# numeric
+ 'imgdir=s' => \$imageDir, # string
+ 'ignore=s' => \$ignore, # string
+ 'other=s' => \$other, # string
+ 'c|clear' => \$clear, # flag
+ 'np|nopreview' => \$nopreview, # flag
+ 'e|eps' => \$eps, # flag
+ 'j|jpg' => \$jpg, # flag
+ 'p|png' => \$png, # flag
+ 'P|ppm' => \$ppm, # flag
+ 's|svg' => \$svg, # flag
+ 'a|all' => \$all, # flag
+ 'miktex' => \$miktex, # flag
+ 'nopdf' => \$nopdf, # flag
+ 'o|output' => \$output, # flag
+ 'xetex' => \$xetex, # flag
+ 'latex' => \$latex, # flag
+ 'luatex' => \$luatex,# flag
+ 'ns|nosource' => \$noSource, # flag
+ 'Verbose' => \$Verbose,
+) or die $usage;
# help functions
-sub errorUsage { die "Error: @_ (try --help for more information)\n"; }
+sub errorUsage { die "@_ (try ltximg --help for more information)\n"; }
# options for command line
if ($::opt_help) {
@@ -128,7 +343,6 @@ if ($::opt_help) {
}
if ($::opt_version) {
print $title;
- print $copyright;
exit(0);
}
if ($::opt_license) {
@@ -145,11 +359,12 @@ if ($xetex) {
if ($luatex) {
$luatex = 1;
}
-if ($pdf) {
- $pdf = 1;
+
+if ($nopdf) {
+ $nopdf = 1;
}
if ($eps) {
- $pdf =$eps = 1;
+ $eps = 1;
}
if ($jpg) {
$jpg = 1;
@@ -160,357 +375,649 @@ if ($png) {
if ($ppm) {
$ppm = 1;
}
-if ($^O eq 'MSWin32'){
- $GSCMD = "gswin32c";
-}
-if ($^O eq 'MSWin64'){
- $GSCMD = "gswin64c";
-}
-if ($useppm){
- $ppm = $useppm = 1;
-}
-if ($usemog){
- $pdf = $usemog = 1;
+if ($svg) {
+ $svg = 1;
}
if ($all){
- $pdf =$eps = $png = $jpg = 1;
+ $eps = $png = $jpg = 1;
}
-## Create image dir
-if (! -e $imageDir) {
- mkdir($imageDir,0744) or die "Can't create $imageDir";
+
+if ($nopreview) {
+ $nopreview= 1;
+}
+
+if ($output) {
+ $output= 1;
}
+if ($miktex) {
+ $miktex= 1;
+}
# open file
+
my $InputFilename = "";
@ARGV > 0 or errorUsage "Input filename missing";
@ARGV < 2 or errorUsage "Unknown option or too many input files";
$InputFilename = $ARGV[0];
-
-# end open file
-my @SuffixList = ( ".tex", "", ".ltx" ); # possible extensions
-my ( $name, $path, $ext ) = fileparse( $ARGV[0], @SuffixList );
-if ( $ext eq "" ) { $ext = ".tex"; } # me need the extension as well
-my $TeXfile = "$path$name$ext";
-# Define in file
-my $archivo_entrada = shift;
+#--------------------- Arreglo de la extensión ------------------------#
+my @SuffixList = ('.tex', '', '.ltx'); # posible extensión
+my ($name, $path, $ext) = fileparse($ARGV[0], @SuffixList);
+$ext = '.tex' if not $ext;
-# Read in file
-open my $ENTRADA, '<', $archivo_entrada;
-my $archivo;
-{
- local $/;
- $archivo = <$ENTRADA>;
-}
-close $ENTRADA;
-## cambiar
-$archivo =~
-s/(?<inicio>\\begin\{)(?<verb>verbatim|verbatim\*|lstlisting|LTXexample|Verbatim|comment|alltt|minted|tcblisting|xcomment|$skip) (?:\})
-/\\begin\{nopreview}
-$+{inicio}$+{verb}\}/gmxs;
-
-$archivo =~
-s/(?<fin>\\end\{)(?<verb>verbatim|verbatim\*|lstlisting|LTXexample|Verbatim|comment|alltt|minted|tcblisting|xcomment|$skip) (?:\})
-/$+{fin}$+{verb}\}
-\\end\{nopreview}/gmxs;
-# Save
-open my $SALIDA, '>', "$tempDir/$name-tmp.tex";
-print $SALIDA $archivo;
-close $SALIDA;
-
-# Add preview in preamble
+#---------------- Creamos el directorio para las imágenes -------------#
+-e $imageDir or mkdir($imageDir,0744) or die "No puedo crear $imageDir: $!\n";
-open my $INFILE,'<', "$tempDir/$name-tmp.tex";
-open my $OUTFIlE,'>',"$tempDir/$name-fig.tex";
-print $OUTFIlE "\\AtBeginDocument\{\n";
- if($xetex){
- print $OUTFIlE "\\RequirePackage\[xetex,active,tightpage\]\{preview\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{tikzpicture\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{pspicture\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{$other\}\}\n";
- }
- elsif($latex){
- print $OUTFIlE "\\RequirePackage\[active,tightpage\]\{preview\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{pspicture\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{$other\}\}\n";
- }
- else {
- print $OUTFIlE "\\RequirePackage\[pdftex,active,tightpage\]\{preview\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{tikzpicture\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{$other\}\}\n";
- }
-
- while ( my $line = <$INFILE> ) {
- print $OUTFIlE $line;
- }
-close $INFILE;
-close $OUTFIlE;
-
-if ($clear) {unlink "$tempDir/$name-tmp.tex";}
-
-# Parser inline verbatim
+# Define in file
+my $archivo_entrada = shift;
-## Lectura del archivo
-open my $PARSER, '<', "$tempDir/$name-fig.tex";
-undef $/; # read al file
-my $file_PARSER = <$PARSER>;
-close $PARSER;
+# Standart line ltximg run
+print "$program $nv, $copyright";
-## Partición del documento
-my($cabeza,$cuerpo,$final) = $file_PARSER =~ m/\A (.+? ^\\begin{document}) \s* (.+?) \s* (^ \\end{document}) \s* \z/msx;
-
-## Cambios a realizar
+##---------------------------- PARTE 1 -------------------------------##
+#------------ Creamos un hash con los cambios para verbatim -----------#
my %cambios = (
+# pst/tikz set
+ '\psset' => '\PSSET',
+ '\tikzset' => '\TIKZSET',
+# pspicture
'\pspicture' => '\TRICKS',
'\endpspicture' => '\ENDTRICKS',
-
+# pspicture
'\begin{pspicture' => '\begin{TRICKS',
'\end{pspicture' => '\end{TRICKS',
-
+# postscript
'\begin{postscript}' => '\begin{POSTRICKS}',
'\end{postscript}' => '\end{POSTRICKS}',
-
- '\begin{tikzpicture' => '\begin{TIKZPICTURE',
- '\end{tikzpicture' => '\end{TIKZPICTURE',
-
- "\\begin\{$other" => '\begin{OTHER',
- "\\end\{$other" => '\end{OTHER',
+# $other
+ "\\begin\{$other" => '\begin{OTHER',
+ "\\end\{$other" => '\end{OTHER',
+# document
+ '\begin{document}' => '\begin{DOCTRICKS}',
+ '\end{document}' => '\end{DOCTRICKS}',
+# tikzpicture
+ '\begin{tikzpicture}' => '\begin{TIKZPICTURE}',
+ '\end{tikzpicture}' => '\end{TIKZPICTURE}',
+# pgfinterruptpicture
+ '\begin{pgfinterruptpicture'=> '\begin{PGFINTERRUPTPICTURE',
+ '\end{pgfinterruptpicture' => '\end{PGFINTERRUPTPICTURE',
+# pgfpicture
+ '\begin{pgfpicture}' => '\begin{PGFPICTURE}',
+ '\end{pgfpicture}' => '\end{PGFPICTURE}',
+# ganttchart
+ '\begin{ganttchart}' => '\begin{GANTTCHART}',
+ '\end{ganttchart}' => '\end{GANTTCHART}',
+# circuitikz
+ '\begin{circuitikz}' => '\begin{CIRCUITIKZ}',
+ '\end{circuitikz}' => '\end{CIRCUITIKZ}',
+# forest
+ '\begin{forest}' => '\begin{FOREST}',
+ '\end{forest}' => '\end{FOREST}',
+# tikzcd
+ '\begin{tikzcd}' => '\begin{TIKZCD}',
+ '\end{tikzcd}' => '\end{TIKZCD}',
+# dependency
+ '\begin{dependency}' => '\begin{DEPENDENCY}',
+ '\end{dependency}' => '\end{DEPENDENCY}',
);
-
-
-## Variables y constantes
+
+#------------------------ Coment inline Verbatim ----------------------#
+open my $ENTRADA, '<', "$archivo_entrada";
+my $archivo;
+{
+ local $/;
+ $archivo = <$ENTRADA>;
+}
+close $ENTRADA;
+
+# Variables y constantes
my $no_del = "\0";
my $del = $no_del;
-
-## Reglas
+
+# Reglas
my $llaves = qr/\{ .+? \} /x;
my $no_corchete = qr/(?:\[ .+? \])? /x;
my $delimitador = qr/\{ (?<del>.+?) \} /x;
-my $verb = qr/verb [*]? /ix;
+my $verb = qr/(spv|v|V)erb [*]? /ix;
my $lst = qr/lstinline (?!\*) $no_corchete /ix;
my $mint = qr/mint (?!\*) $no_corchete $llaves /ix;
-my $marca = qr/\\ (?:$verb | $lst | $mint) (\S) .+? \g{-1} /x;
+my $marca = qr/\\ (?:$verb | $lst | $mint ) (\S) .+? \g{-1} /x;
my $comentario = qr/^ \s* \%+ .+? $ /mx;
my $definedel = qr/\\ (?: DefineShortVerb | lstMakeShortInline ) $no_corchete $delimitador /ix;
my $indefinedel = qr/\\ (?: UndefineShortVerb | lstDeleteShortInline) $llaves /ix;
+
+while ($archivo =~
+ / $marca
+ | $comentario
+ | $definedel
+ | $indefinedel
+ | $del .+? $del # delimitado
+ /pgmx) {
+ my($pos_inicial, $pos_final) = ($-[0], $+[0]); # posiciones
+ my $encontrado = ${^MATCH}; # lo encontrado
-# Changes
-
-while ($cuerpo =~
- / $marca
- | $comentario
- | $definedel
- | $indefinedel
- | $del .+? $del # delimitado
- /gimx) {
-
- my($pos_inicial, $pos_final) = ($-[0], $+[0]); # posiciones
- my $encontrado = ${^MATCH}; # lo encontrado
-
- given ($encontrado) {
- when (/$definedel/) { # definimos delimitador
- $del = $+{del};
- $del = "\Q$+{del}" if substr($del,0,1) ne '\\'; # es necesario "escapar" el delimitador
- }
- when (/$indefinedel/) { # indefinimos delimitador
- $del = $no_del;
+ if ($encontrado =~ /$definedel/){ # definimos delimitador
+ $del = $+{del};
+ $del = "\Q$+{del}" if substr($del,0,1) ne '\\'; # es necesario "escapar" el delimitador
+ }
+ elsif($encontrado =~ /$indefinedel/) { # indefinimos delimitador
+ $del = $no_del;
}
- default { # Aquí se hacen los cambios
- while (my($busco, $cambio) = each %cambios) {
-
- $encontrado =~ s/\Q$busco\E/$cambio/g; # es necesario escapar $busco, ya que contiene caracteres extraños
- }
-
- substr $cuerpo, $pos_inicial, $pos_final-$pos_inicial, $encontrado; # insertamos los nuevos cambios
+ else { # aquí se hacen los cambios
+ while (my($busco, $cambio) = each %cambios) {
+ $encontrado =~ s/\Q$busco\E/$cambio/g; # es necesario escapar $busco
+ }
+ substr $archivo, $pos_inicial, $pos_final-$pos_inicial, $encontrado; # insertamos los nuevos cambios
- pos($cuerpo)= $pos_inicial + length $encontrado; # reposicionamos la siguiente búsqueda
+ pos($archivo)= $pos_inicial + length $encontrado; # re posicionamos la siguiente búsqueda
}
- }
}
-
-# Write
-open my $OUTPARSER, '>', "$tempDir/$name-fig.tex";
-print $OUTPARSER "$cabeza\n$cuerpo\n$final\n";
-close $OUTPARSER;
+# Constantes
+my $BP = '\\\\begin{postscript}';
+my $EP = '\\\\end{postscript}';
+my $BPL = '\begin{postscript}';
+my $EPL = '\end{postscript}';
+my $sipgf = 'pgfpicture';
+my $nopgf = 'pgfinterruptpicture';
+my $graphics = "graphic=\{\[scale=1\]$imageDir/$name-fig";
-# Compiling files...
+# directorio en el cual están las imágenes
+my $dir = "$tempDir/$imageDir";
-# Using LaTeX
+#--------------------- Coment Verbatim environment --------------------#
-if($latex){
- print "Compiled using LaTeX\n";
- system("latex -interaction=batchmode $tempDir/$name-fig.tex");
- system("dvips -q -Ppdf $tempDir/$name-fig.dvi");
- system("ps2pdf -dPDFSETTINGS=\/prepress $tempDir/$name-fig.ps $tempDir/$name-fig.pdf");
-if ($clear) {
- unlink "$tempDir/$name-fig.dvi";
- unlink "$tempDir/$name-fig.ps";
- unlink "$tempDir/$name-fig.log";
- unlink "$tempDir/$name-fig.aux";
- unlink "$tempDir/$name-fig.tex";
- }
- }
-
-# Using XeLaTeX
+my @lineas = split /\n/, $archivo;
-elsif($xetex){
- print "Compiled using (Xe)LaTeX\n";
- system("xelatex -interaction=batchmode $tempDir/$name-fig.tex");
-if ($clear) {
- unlink "$tempDir/$name-fig.log";
- unlink "$tempDir/$name-fig.aux";
- unlink "$tempDir/$name-fig.tex";
- }
- }
-
-# Using LuaLaTeX
+# Verbatim environments
+my $ENTORNO = qr/(?: (v|V)erbatim\*?| PSTexample | LTXexample| $ignore\*? | PSTcode | tcblisting\*? | spverbatim | minted | lstlisting | alltt | comment\*? | xcomment)/xi;
-elsif($luatex){
- print "Compiled using (lua)LaTeX\n";
- system("lualatex -interaction=batchmode $tempDir/$name-fig.tex");
-if ($clear) {
- unlink "$tempDir/$name-fig.log";
- unlink "$tempDir/$name-fig.aux";
- unlink "$tempDir/$name-fig.tex";
- }
- }
+# postscript environment
+my $POSTSCRIPT = qr/(?: postscript)/xi;
-# Using pdfLaTeX (default)
-
-else{
- print "Compiled using (pdf)LaTeX\n";
- system("pdflatex -interaction=batchmode $tempDir/$name-fig.tex");
-if ($clear) {
- unlink "$tempDir/$name-fig.log";
- unlink "$tempDir/$name-fig.aux";
- unlink "$tempDir/$name-fig.tex";
- }
- }
-
-# Croping
+# tikzpicture environment
+my $TIKZENV = qr/(?: tikzpicture)/xi;
+#
+my $DEL;
+
+# tcbverb verbatim
+my $tcbverb = qr/\\(?:tcboxverb|myverb)/;
+my $arg_brac = qr/(?:\[.+?\])?/;
+my $arg_curl = qr/\{(.+)\}/;
+
+# coment verbatim environment
+for (@lineas) {
+ if (/\\begin\{($ENTORNO)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ }
+}
+# coment tcolorbox inline
+for (@lineas) {
+ if (m/$tcbverb$arg_brac$arg_curl/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ } # close
+ }
+# remove postscript from hash
+delete @cambios{'\begin{postscript}','\end{postscript}'};
+# coment in postscript environment
+for (@lineas) {
+ if (/\\begin\{($POSTSCRIPT)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ } # close postcript environment
+}
+# remove tikzpicture from hash
+delete @cambios{'\begin{tikzpicture}','\end{tikzpicture}'};
+# coment in tikzpicture environment
+for (@lineas) {
+ if (/\\begin\{($TIKZENV)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ } # close TIKZ environment
+}
+
+undef %cambios; # erase hash
+
+#------------- Convert ALL into Postscript environments ---------------#
+
+$archivo = join("\n", @lineas);
+## Partición del documento
+
+my($cabeza,$cuerpo,$final) = $archivo =~ m/\A (.+?) (\\begin{document} .+?)(\\end{document}.*)\z/msx;
+
+# \pspicture to \begin{pspicture}
+$cuerpo =~ s/\\pspicture(\*)?(.+?)\\endpspicture/\\begin{pspicture$1}$2\\end{pspicture$1}/gmsx;
+
+# pspicture to Postscript
+$cuerpo =~ s/
+ (
+ (?:\\psset\{[^\}]+\}.*?)?
+ (?:\\begin\{pspicture(\*)?\})
+ .*?
+ (?:\\end\{pspicture(\*)?\})
+ )
+ /$BPL\n$1\n$EPL/gmsx;
+
+# pgfpicture to Postscript
+$cuerpo =~ s/
+ (
+ \\begin{$sipgf}
+ .*?
+ (
+ \\begin{$nopgf}
+ .+?
+ \\end{$nopgf}
+ .*?
+ )*?
+ \\end{$sipgf}
+ )
+ /$BPL\n$1\n$EPL/gmsx;
+
+# tikz to Postscript
+$cuerpo =~ s/
+ (
+ (?:\\tikzset(\{(?:\{.*?\}|[^\{])*\}).*?)? # si está lo guardo
+ (?:\\begin\{tikzpicture\}) # aquí comienza la búsqueda
+ .*? # guardo el contenido en $1
+ (?:\\end\{tikzpicture\}) # termina la búsqueda
+ ) # cierra $1
+ /$BPL\n$1\n$EPL/gmsx;
+
+# rest to PostScript
+my $export = qr/(forest|ganttchart|tikzcd|circuitikz|dependency|$other\*?)/x;
+
+$cuerpo =~ s/(\\begin\{($export)\} (.*?) \\end\{\g{-2}\})/$BPL\n$1\n$EPL/gmsx;
+
+#-------------------------- Reverse changes ---------------------------#
+$archivo = "$cabeza$cuerpo$final";
+my %cambios = (
+# pst/tikz set
+ '\PSSET' => '\psset',
+ '\TIKZSET' => '\tikzset',
+# pspicture
+ '\TRICKS' => '\pspicture',
+ '\ENDTRICKS' => '\endpspicture',
+# pspicture
+ '\begin{TRICKS' => '\begin{pspicture',
+ '\end{TRICKS' => '\end{pspicture',
+# $other
+ '\begin{OTHER' => "\\begin\{$other",
+ '\end{OTHER' => "\\end\{$other",
+# document
+ '\begin{DOCTRICKS}' => '\begin{document}',
+ '\end{DOCTRICKS}' => '\end{document}',
+# tikzpicture
+ '\begin{TIKZPICTURE}' => '\begin{tikzpicture}',
+ '\end{TIKZPICTURE}' => '\end{tikzpicture}',
+# pgfinterruptpicture
+ '\begin{PGFINTERRUPTPICTURE'=> '\begin{pgfinterruptpicture',
+ '\end{PGFINTERRUPTPICTURE' => '\end{pgfinterruptpicture',
+# pgfpicture
+ '\begin{PGFPICTURE}' => '\begin{pgfpicture}',
+ '\end{PGFPICTURE}' => '\end{pgfpicture}',
+# ganttchart
+ '\begin{GANTTCHART}' => '\begin{ganttchart}',
+ '\end{GANTTCHART}' => '\end{ganttchart}',
+# circuitikz
+ '\begin{CIRCUITIKZ}' => '\begin{circuitikz}',
+ '\end{CIRCUITIKZ}' => '\end{circuitikz}',
+# forest
+ '\begin{FOREST}' => '\begin{forest}',
+ '\end{FOREST}' => '\end{forest}',
+# tikzcd
+ '\begin{TIKZCD}' => '\begin{tikzcd}',
+ '\end{TIKZCD}' => '\end{tikzcd}',
+# dependency
+ '\begin{DEPENDENCY}' => '\begin{dependency}',
+ '\end{DEPENDENCY}' => '\end{dependency}',
+);
-print "Done, $name-fig.pdf need croping, using pdfcrop whit margin $margins\n";
-system("pdfcrop --margins $margins $tempDir/$name-fig.pdf $tempDir/$name-fig.pdf");
+#-------------------------- Back Postscript ---------------------------#
-# Gs for split file
+my @lineas = split /\n/, $archivo;
+# reverse in postscript environment
+for (@lineas) {
+ if (/\\begin\{($POSTSCRIPT)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ } # close postscript environment changes
+}
-if ($pdf) {
-print "Create pdf figs in $imageDir dir using Ghostscript \($GSCMD\)\n";
-system("$GSCMD -q -sDEVICE=pdfwrite -dPDFSETTINGS=\/prepress -dNOPAUSE -dBATCH -sOutputFile=$imageDir/$name-fig-%d.pdf $tempDir/$name-fig.pdf");
+# join changes
+$archivo = join("\n", @lineas);
-# Delete last pdf (bug from gs)
+#--------------- Extract source code for PST/PGF/TIKZ -----------------#
+# Dividir el archivo
+my($cabeza,$cuerpo,$final) = $archivo =~ m/\A (.+?) (\\begin{document} .+?)(\\end{document}.*)\z/msx;
-my $i = 1;
-while (-e "$imageDir/$name-fig-${i}.pdf") { # if exisit search
- $i++; # next
-} # search end
+# Poner el atributo añadido a PostScript
+while ($cuerpo =~ /\\begin\{postscript\}/gsm) {
-$i--; # back the last
+ my $corchetes = $1;
+ my($pos_inicial, $pos_final) = ($-[1], $+[1]); # posición donde están los corchetes
-unlink "$imageDir/$name-fig-${i}.pdf";
+ if (not $corchetes) {
+ $pos_inicial = $pos_final = $+[0]; # si no hay corchetes, nos ponemos al final de \begin
+ }
+ if (not $corchetes or $corchetes =~ /\[\s*\]/) { # si no hay corchetes, o están vacíos,
+ $corchetes = "[$graphics-$exacount}]"; # ponemos los nuestros
+ }
+ substr($cuerpo, $pos_inicial, $pos_final - $pos_inicial) = $corchetes;
+ pos($cuerpo) = $pos_inicial + length $corchetes; # reposicionamos la búsqueda de la exp. reg.
+}
+continue {
+ $exacount++;
+}
+# Delte source files
+if (-e "$imageDir/$name-fig-1$ext") {
+unlink <"$imageDir/$name-fig-*$ext">;
+}
+#---------------------- Extract source code in images -----------------#
+while ($cuerpo =~ /$BP\[.+?(?<img_src_name>$imageDir\/.+?-\d+)\}\](?<code>.+?)(?=$EP)/gsm) {
+ open my $SALIDA, '>', "$+{'img_src_name'}$ext";
+ print $SALIDA <<"EOC";
+$cabeza\\pagestyle{empty}\n\\begin{document}$+{'code'}\\end{document}
+EOC
+close $SALIDA;
+}
+#--------------- Create a one file whit all figs file -----------------#
+if ($nopreview) {
+if (-e "$imageDir/$name-fig-1$ext") {
+# 1- Leer los source files
+my @pstexafiles = glob("$imageDir/$name-fig-*$ext");
+
+# 2- Ordenar según el índice y extención
+@pstexafiles =
+ map { $_->[1] }
+ sort { $a->[0] <=> $b->[0] }
+ map { [ ($_ =~ /(\d+$ext)/), $_ ] }
+ @pstexafiles;
+
+# 3- Bucle para leer las secciones
+my @almacen;
+for my $exafile (@pstexafiles) {
+
+ # 3.1- Leer el archivo
+ open my $FH, '<', $exafile; #
+ my $tex = join q{}, <$FH>; #
+ close $FH;
+
+ # 3.2- Extraer la parte que nos interesa
+ my($pedazo) = $tex =~ m/\\begin\{document\}\s*(.+?)\s*\\end\{document\}/sm;
+
+ # 3.3- Almacenamos, si hemos encontrado algo
+ push @almacen, $pedazo if $pedazo;
}
+# 4- Salida
-# Fix pdftops error message in windows
+open my $SALIDA, '>', "$tempDir/$name-fig$ext";
+print $SALIDA "$cabeza\\pagestyle{empty}\n\\begin\{document\}\n";
-if ($^O eq 'MSWin32' || $^O eq 'MSWin64'){
+my $fig = 1;
+for my $item (@almacen) {
+ print $SALIDA $item;
+ print $SALIDA "\n%% fig $fig\n";
+ print $SALIDA "\\newpage\n";
+ $fig++;
+}
+
+print $SALIDA '\end{document}';
+close $SALIDA;
+ } # close join files
+} # close $nopreview
+else {
+my $opcion = $xetex ? 'xetex,'
+ : $latex ? ''
+ : 'pdftex,'
+ ;
+
+my $preview = <<"EXTRA";
+\\AtBeginDocument\{%
+\\RequirePackage\[${opcion}active,tightpage\]\{preview\}%
+\\renewcommand\\PreviewBbAdjust\{-60pt -60pt 60pt 60pt\}%
+\\newenvironment\{postscript\}\{\}\{\}%
+\\PreviewEnvironment\{postscript\}\}%
+EXTRA
+ # write
+ open my $SALIDA, '>', "$tempDir/$name-fig$ext";
+ print $SALIDA $preview . $archivo;
+ close $SALIDA;
+}
+
+#---------------------- Create images files ---------------------------#
+# Define compilers
+my $compile = $xetex ? 'xelatex'
+ : $luatex ? 'lualatex'
+ : $latex ? 'latex'
+ : 'pdftex'
+ ;
+my $opt_compile = $miktex ? '--enable-write18 --interaction=batchmode'
+ : '--shell-escape --interaction=batchmode'
+ ;
+
+# Option for gs
+my $opt_gspdf='-q -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress';
+my $opt_gspng="-q -dSAFER -sDEVICE=pngalpha -r$DPI";
+my $opt_gsjpg="-q -dSAFER -sDEVICE=jpeg -r$DPI -dJPEGQ=100 -dGraphicsAlphaBits=4 -dTextAlphaBits=4";
+
+# Option for pdfcrop
+my $opt_crop= $xetex ? "--xetex --margins $margins"
+ : $luatex ? "--luatex --margins $margins"
+ : $latex ? "--margins $margins"
+ : "--pdftex --margins $margins"
+ ;
+# Fix pdftops error message in windows
+if ($^O eq 'MSWin32' or $^O eq 'MSWin64'){
open my $ppmconf, '>', "$tempDir/xpd";
print $ppmconf <<'EOH';
errQuiet yes
EOH
close $ppmconf;
}
-
-# Create eps files using pdftops
-
-if ($eps) {
-print "Create eps figs in $imageDir dir using pdftops\n";
-# Search pdf in $imageDir
- for my $image_pdf (<$imageDir/*.pdf>) {
-
-if ($^O eq 'MSWin32' || $^O eq 'MSWin64'){
- system("pdftops -cfg $tempDir/xpd -q -level3 -eps $image_pdf");
- }
+#-------------------------- Compiling image file ----------------------#
+if($nopreview){
+ print "Create $name-fig.pdf in $imageDir dir whit all PGF/TIKZ/PST using $compile\n";
+ }
else{
- system("pdftops -level3 -eps $image_pdf");
- }
- }
- }
-
-# Create ppm files and renamig files
-
-if($ppm){
-print "Create ppm figs in $imageDir dir using pdftoppm\n";
-if ($^O eq 'MSWin32' || $^O eq 'MSWin64'){
- system("pdftoppm -cfg $tempDir/xpd -q -r $DPI $tempDir/$name-fig.pdf $imageDir/$name-fig");
+ print "Create $name-fig.pdf in $imageDir dir whit all PGF/TIKZ/PST using $compile and preview package\n";
+ }
+
+# Run TeX mode
+system("$compile $opt_compile -output-directory=$imageDir $tempDir/$name-fig$ext");
+if($latex){
+ system("dvips -q -Ppdf -o $imageDir/$name-fig.ps $imageDir/$name-fig.dvi");
+ system("ps2pdf -dPDFSETTINGS=/prepress $imageDir/$name-fig.ps $imageDir/$name-fig.pdf");
+ }
+print "The file $imageDir/$name-fig.pdf need a cropping using pdfcrop whit options: $opt_crop\n";
+system("pdfcrop $opt_crop $imageDir/$name-fig.pdf $imageDir/$name-fig.pdf");
+
+##-------------------------- Create image formats ----------------------#
+
+opendir(my $DIR, $imageDir);
+my @figs = sort readdir $DIR;
+closedir $DIR;
+for my $fig (@figs) {
+if ($fig =~ /(?<fig>$name-fig-)(?<num>\d+)$ext/) {
+print "Create $imageDir/$name-fig-$+{num} from $name$ext\r";
+# PDF format
+if (!$nopdf) {
+system("$::opt_gscmd $opt_gspdf -o $imageDir/$name-fig-%1d.pdf $imageDir/$name-fig.pdf");
+}
+# PNG format
+if ($png) {
+system("$::opt_gscmd $opt_gspng -o $imageDir/$name-fig-%1d.png $imageDir/$name-fig.pdf");
}
-else{
- system("pdftoppm -r $DPI $tempDir/$name-fig.pdf $imageDir/$name-fig");
+# JPEG format
+if ($jpg) {
+system("$::opt_gscmd $opt_gsjpg -o $imageDir/$name-fig-%1d.jpg $imageDir/$name-fig.pdf");
+ }
+
+# SVG format pdf2svg
+if ($svg) {
+ system("pdf2svg $imageDir/$name-fig.pdf $imageDir/$+{fig}%1d.svg all");
+ }
+# EPS format
+if ($eps) {
+ if ($^O eq 'MSWin32' or $^O eq 'MSWin64'){
+ system("pdftops -cfg $tempDir/xpd -q -eps -f $+{num} -l $+{num} $imageDir/$name-fig.pdf $imageDir/$+{fig}$+{num}.eps");
+ }else{
+ system("pdftops -q -eps -f $+{num} -l $+{num} $imageDir/$name-fig.pdf $imageDir/$+{fig}$+{num}.eps");
+ }
+ } # close EPS
+# PPM format
+if ($ppm) {
+ if ($^O eq 'MSWin32' or $^O eq 'MSWin64'){
+ system("pdftoppm -cfg $tempDir/xpd -q -r $DPI -f $+{num} -l $+{num} $imageDir/$name-fig.pdf $imageDir/$+{fig}$+{num}");
}
-
-# Renaming .ppm (only need in windows)
-
-if ($^O eq 'MSWin32' || $^O eq 'MSWin64'){
-my $dren = "$tempDir/$imageDir";
-my $fichero = '';
-my $ppmren = '';
-my $renNo = 1;
-if(opendir(DIR,$dren)){
-foreach (readdir DIR){
- $fichero = $_;
- if ( $fichero =~ /($name-fig-)(\d+|\d+[-]\d+).ppm/) {
- my $renNo = int($2);
- my $newname="$1$renNo.ppm";
- $ppmren = rename("$dren/$fichero","$dren/$newname");
- }
- }
+ else{
+ system("pdftoppm -q -r $DPI -f $+{num} -l $+{num} $imageDir/$name-fig.pdf $imageDir/$+{fig}$+{num}");
}
-closedir DIR;
- }
- }
+ } # close PPM
+ } # close if ($fig =
+} # close for
-# Change dir and create png/jpg formats using mogrify and ppm
+## Renaming PPM
+if ($ppm) {
+if (opendir(DIR,$dir)) { # abro el directorio
+ while (my $oldname = readdir DIR) { # lo recorro
+ # el nuevo nombre es fruto de una sustitución
+ my $newname = $oldname =~ s/^($name-(fig|exa)-\d+)(-\d+).ppm$/$1 . ".ppm"/re;
+
+ if ($oldname ne $newname) { # comprobación
+ rename("$dir/$oldname", "$dir/$newname"); # renombro
+ }
+ }
+ closedir DIR;
+ } # close rename ppm
+} # close ppm
+
+#------- Creating output file whitout PGF/PST/TIKZ code ---------------#
+if ($output) {
+print "Create file $name-out$ext whitout PGF/PST/TIKZ code\n";
+
+#----------------- Convert Postscript to includegraphics --------------#
+my $grap="\\includegraphics[scale=1]{$name-fig-";
+my $close = '}';
+my $IMGno = 1;
+
+$cuerpo =~ s/$BP.+?$EP/$grap@{[$IMGno++]}$close/msg;
+
+#------------------------ Clean output file --------------------------#
+# append postscript to hash
+$cambios{'\begin{POSTRICKS}'} = '\begin{postscript}';
+$cambios{'\end{POSTRICKS}'} = '\end{postscript}';
+
+# Constantes
+my $BEGINDOC = quotemeta('\begin{document}');
+my $USEPACK = quotemeta('\usepackage');
+my $REQPACK = quotemeta('\usepackage');
+my $GRAPHICX = quotemeta('{graphicx}');
+
+# Exp. Reg.
+my $CORCHETES = qr/\[ [^]]*? \]/x;
+my $PALABRAS = qr/\b (?: pst-\w+ | pstricks (?: -add )? | psfrag |psgo |vaucanson-g| auto-pst-pdf | graphicx )/x;
+my $FAMILIA = qr/\{ \s* $PALABRAS (?: \s* [,] \s* $PALABRAS )* \s* \}/x;
+
+# comentar
+$cabeza =~ s/ ^ ($USEPACK $CORCHETES $GRAPHICX) /%$1/msxg;
+
+# eliminar líneas enteras
+$cabeza =~ s/ ^ $USEPACK (?: $CORCHETES )? $FAMILIA \n//msxg;
+
+# eliminar palabras sueltas
+$cabeza =~ s/ (?: ^ $USEPACK \{ | \G) [^}]*? \K (,?) \s* $PALABRAS (\s*) (,?) /$1 and $3 ? ',' : $1 ? $2 : ''/gemsx;
+
+# Añadir
+$cabeza .= <<"EXTRA";
+\\usepackage{graphicx}
+\\graphicspath{{$imageDir/}}
+\\usepackage{grfext}
+\\PrependGraphicsExtensions*{.pdf}
+EXTRA
+
+# Clear PST content in preamble
+$cabeza =~ s/\\usepackage\{\}/% delete/gmsx;
+$cabeza =~ s/\\psset\{.+?\}/% \\psset delete/gmsx;
+$cabeza =~ s/\\SpecialCoor/% \\SpecialCoor/gmsx;
+
+# Recorremos el archivo y realizamos los cambios
+while (my($busco, $cambio) = each %cambios) {
+ $cabeza =~ s/\Q$busco\E/$cambio/g;
+ $cuerpo =~ s/\Q$busco\E/$cambio/g;
+ }
+
+# write
+open my $SALIDA, '>', "$tempDir/$name-out$ext";
+print $SALIDA "$cabeza$cuerpo$final";
+close $SALIDA;
-if($usemog){
-chdir ($imageDir) or die "$imageDir not exist\n";
-if ($png) {
-print "Create png transparent in $imageDir dir using mogrify and pdf\n";
-system("mogrify $IMO -define png:format=png32 -define png:compression-filter=4 -quality 100 -transparent white -density $DPI -format png \*\.pdf");
- }
-if ($jpg) {
-print "Create jpg figs in $imageDir dir using mogrify and pdf\n";
-system("mogrify $IMO -quality 100 -density $DPI -format jpg \*\.pdf");
+# compile output file
+
+if ($xetex){
+ system("xelatex $opt_compile $tempDir/$name-out$ext");
+ } # xetex
+elsif($luatex){
+ system("lualatex $opt_compile $tempDir/$name-out$ext");
+ } # luatex
+else{
+ system("pdflatex $opt_compile $tempDir/$name-out$ext");
+ } # pdftex
+
+}# close output file
+
+#--------------------------------- Clean ------------------------------#
+if ($clear) {
+my @del_aux_tex;
+find(\&del_aux_tex, $tempDir);
+sub del_aux_tex{
+my $auximgfile = $_;
+# search .(aux|log)
+if(-f $auximgfile && $auximgfile =~ /$name-out\.(aux|log)$/){
+push @del_aux_tex, $File::Find::name;
+ }
+if(-f $auximgfile && $auximgfile =~ /$name-fig$ext/){
+push @del_aux_tex, $File::Find::name;
}
}
-elsif($useppm){
-chdir ($imageDir) or die "$imageDir not exist\n";
-if ($png) {
-print "Create png figs in $imageDir dir using mogrify and ppm\n";
-system("mogrify $IMO -quality 100 -define png:format=png32 -define png:compression-filter=4 -density $DPI -format png \*\.ppm");
- }
-if ($jpg) {
-print "Create jpg figs in $imageDir dir using mogrify and ppm\n";
-system("mogrify $IMO -quality 100 -density $DPI -format jpg \*\.ppm");
+unlink @del_aux_tex;
+} # close clear in $tempDir
+
+if ($clear) {
+my @del_tmp;
+find(\&del_tmp, $imageDir);
+sub del_tmp{
+my $auximgfile = $_;
+# search .(aux|log)
+if(-f $auximgfile && $auximgfile =~ /$name-fig\.(aux|dvi|log|ps|pdf)/){
+push @del_tmp, $File::Find::name;
}
}
-else{
-# Create png using gs (default)
+unlink @del_tmp;
+} # close clear $name-fig.tex
-if ($png) {
-print "Create png figs in $imageDir dir using Ghostscript \($GSCMD\)\n";
-system("$GSCMD -q -sDEVICE=png16m -r$DPI -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dNOPAUSE -dBATCH -sOutputFile=$imageDir/$name-fig-%d.png $tempDir/$name-fig.pdf");
- }
+# Clear source files
+if ($noSource) {
+unlink <"$imageDir/$name-fig-*$ext">;
+}# end source clear
-if ($jpg) {
-print "Create jpg figs in $imageDir dir using Ghostscript \($GSCMD\)\n";
-system("$GSCMD -q -sDEVICE=jpeg -r$DPI -dJPEGQ=100 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dNOPAUSE -dBATCH -sOutputFile=$imageDir/$name-fig-%d.jpg $tempDir/$name-fig.pdf");
- }
- }
+if ($output) {
+print "Finish, LTXimg create $name-out$ext and put all figures in $imageDir dir\n";
+}else{
+print "Finish, LTXimg create all figures in $imageDir dir\n";
+}
+if ($^O eq 'MSWin32' or $^O eq 'MSWin64'){
+unlink "$tempDir/xpd";
+ }
-print "Finish, all figures are in $imageDir dir\n";
-
__END__
diff --git a/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl b/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl
index f4479f3c852..2044e3aca2a 100755
--- a/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl
+++ b/Build/source/texk/texlive/linked_scripts/texlive/tlmgr.pl
@@ -1,12 +1,12 @@
#!/usr/bin/env perl
-# $Id: tlmgr.pl 36929 2015-04-19 12:26:46Z preining $
+# $Id: tlmgr.pl 36997 2015-04-22 00:21:41Z preining $
#
# Copyright 2008-2015 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
-my $svnrev = '$Revision: 36929 $';
-my $datrev = '$Date: 2015-04-19 14:26:46 +0200 (Sun, 19 Apr 2015) $';
+my $svnrev = '$Revision: 36997 $';
+my $datrev = '$Date: 2015-04-22 02:21:41 +0200 (Wed, 22 Apr 2015) $';
my $tlmgrrevision;
my $prg;
if ($svnrev =~ m/: ([0-9]+) /) {
@@ -279,6 +279,24 @@ sub main {
exit 0;
}
+ #
+ # ACTION massaging
+ # for backward compatibility and usability
+
+ # unify arguments so that the $action contains paper in all cases
+ # and push the first arg back to @ARGV for action_paper processing
+ if ($action =~ /^(paper|xdvi|psutils|pdftex|dvips|dvipdfmx?|context)$/) {
+ unshift(@ARGV, $action);
+ $action = "paper";
+ }
+
+ # backward compatibility with action "show" and "list" from before
+ if ($action =~ /^(show|list)$/) {
+ $action = "info";
+ }
+
+ # now $action should be part of %actionoptions, otherwise this is
+ # an error
if (defined($action) && $action && !exists $actionoptions{$action}) {
die "$prg: unknown action: $action; try --help if you need it.\n";
}
@@ -351,18 +369,6 @@ for the full story.\n";
}
}
- # unify arguments so that the $action contains paper in all cases
- # and push the first arg back to @ARGV for action_paper processing
- if ($action =~ /^(paper|xdvi|psutils|pdftex|dvips|dvipdfmx?|context)$/) {
- unshift(@ARGV, $action);
- $action = "paper";
- }
-
- # backward compatibility with action "show" and "list" from before
- if ($action =~ /^(show|list)$/) {
- $action = "info";
- }
-
# --machine-readable is only supported by update.
if ($::machinereadable &&
$action ne "update" && $action ne "install" && $action ne "option") {
diff --git a/Master/texmf-dist/doc/support/ltximg/CHANGES b/Master/texmf-dist/doc/support/ltximg/CHANGES
new file mode 100644
index 00000000000..ea7d3e82c8f
--- /dev/null
+++ b/Master/texmf-dist/doc/support/ltximg/CHANGES
@@ -0,0 +1,7 @@
+#------------------------------ CHANGES -------------------------------#
+v1.1 2015-04-21 - Change mogrify to gs for image formats
+ - Create output file
+ - Rewrite source code and fix regex
+ - Add more image format
+ - Change date to iso format
+v1.0 2013-12-01 - First public release
diff --git a/Master/texmf-dist/doc/support/ltximg/README b/Master/texmf-dist/doc/support/ltximg/README
index 29e0f955e71..4a783f5a3bc 100644
--- a/Master/texmf-dist/doc/support/ltximg/README
+++ b/Master/texmf-dist/doc/support/ltximg/README
@@ -1,45 +1,51 @@
ltximg is a Perl script which isolates all Tikz or
PSTricks related parts of the TeX document into single
-pdf file, split and convert in eps/pdf/png/jpg format.
+pdf file, split and convert in eps/pdf/png/jpg/svg format.
The advantage of "ltximg" is the ability to discuss the
environments that give problems using the "preview" package
-as "verbatim" in line (verb|...|) or beginning with %, and
+as "verbatim" inline (verb|...|) or beginning with %, and
other environments (LTXexample, Verbatim,etc).
The images files are saved in a subdirectory images.
Syntax: perl ltximg.pl file.tex [options]
-ltximg create a copy for TeX source whit all TiKZ|Pstricks environments
+ltximg create a copy for TeX source whit all PGF|TiKZ|Pstricks environments
and convert all environments into single images (pdf/png/eps/jpg).
- By default search and extract TiKZ environments using (pdf)LaTeX
+ By default search and extract environments using (pdf)LaTeX
and ghostscript (gs).
+Environments suports by LTXimg:
+
+ pspicture tikzpicture pgfpicture forest ganttchart
+ tikzcd circuitikz dependency other postscript
+
Options:
- --h|help - display this help and exit
- --v|version - display version information and exit
- --li|license - display license information and exit
- --imageDir= - the dir for the created images (default images)
- --d|DPI= - dots per inch for gs, pdftoppm and mogrify (default 300)
- --IMO="..." - aditional options for mogrify need double quotes
- --c|clear - delete all temp files
- --xe|xetex - create all image using xelatex (tikz and pstricks)
- --lu|luatex - create all image using lualatex (tikz)
- --la|latex - create all image using latex (pstricks)
- --up|useppm - create jpg and png using mogrify and ppm
- --um|usemog - create jpg and png (transparent) using mogrify and pdf
- --m|margins= - margins for pdfcrop (default 0)
- --pdf - create .pdf files using gs
- --ppm - create .ppm files (need pdftoppm)
- --eps - create .eps files (need pdftops)
- --jpg - create .jpg files (deafult use gs)
- --png - create .png files (deafult use gs)
- --s|skip= - name for skip environmet in input file (default skip)
- --o|other= - name for other export environmet (default other)
- --a|all - create pdf/jpg/png/eps image type
-
-
-
-Pablo González 2013-01-12
+ -h,--help - display this help and exit
+ -l,--license - display license information and exit
+ -v,--version - display version (current 1.2) and exit
+ -d,--dpi=<int> - the dots per inch for images (default 150)
+ -j,--jpg - create .jpg files (need Ghostscript)
+ -p,--png - create .png files (need Ghostscript)
+ -e,--eps - create .eps files (need pdftops)
+ -s,--svg - create .svg files (need pdf2svg)
+ -P,--ppm - create .ppm files (need pdftoppm)
+ -a,--all - create .(pdf,eps,jpg,png) images
+ -c,--clear - delete all temp and aux files
+ -o,--output - create a file-out.tex whitout PGF|TiKZ|PST code
+ -m,--margins=<int> - margins in bp for pdfcrop (default 0)
+ -np,--nopreview - create images files whitout preview package
+ -ns,--nosource - delete all source for images files
+ --miktex - use --enable-write18 for MikTeX users
+ --xetex - using (Xe)LaTeX for create images
+ --latex - using LaTeX for create images
+ --luatex - using (Lua)LaTeX for create images
+ --nopdf - don't create a PDF image files (default off)
+ --other=<string> - search other environment (default other)
+ --ignore=<string> - skip verbatim environment (default ignore)
+ --imgdir=<string> - the folder for images (default images)
+
+
+Pablo González Luengo, 2015-04-21
diff --git a/Master/texmf-dist/doc/support/ltximg/ltximg-doc.pdf b/Master/texmf-dist/doc/support/ltximg/ltximg-doc.pdf
index 3d64cbf462b..90856ffefd2 100644
--- a/Master/texmf-dist/doc/support/ltximg/ltximg-doc.pdf
+++ b/Master/texmf-dist/doc/support/ltximg/ltximg-doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/support/ltximg/ltximg-doc.tex b/Master/texmf-dist/doc/support/ltximg/ltximg-doc.tex
index 9903dcf280a..cfe90a9d057 100644
--- a/Master/texmf-dist/doc/support/ltximg/ltximg-doc.tex
+++ b/Master/texmf-dist/doc/support/ltximg/ltximg-doc.tex
@@ -1,244 +1,337 @@
-\documentclass[11pt]{article}
+\documentclass[10pt]{article}
\usepackage[T1]{fontenc}%
+\usepackage{hologo}%
+\usepackage{fetamont}%
\usepackage{libertine}%
\usepackage{booktabs}%
\usepackage{tabularx}%
-\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
-\usepackage[margin=0.85in,letterpaper]{geometry}
-\usepackage[scaled=0.9]{inconsolata}
-\usepackage{listings}
-
+\usepackage{tcolorbox}%
+\tcbuselibrary{documentation}%
+\usepackage[margin=1.0in,letterpaper]{geometry}%
+\usepackage[scaled=0.9]{inconsolata}%
+\usepackage{listings}%
+% colors
\definecolor{lightgrey}{rgb}{0.9,0.9,0.9}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\definecolor{darkred}{rgb}{0.6,0,0}
\definecolor{myblue}{RGB}{20,105,176}
\definecolor{darkgreen}{rgb}{0,0.6,0}
-
+% languaje
\lstdefinelanguage{mytex}[LaTeX]{TeX}{
- columns=flexible,
- frame=single,
- framerule=0pt,%
- backgroundcolor=\color{gray!10},%
- xleftmargin=\fboxsep,%
- xrightmargin=\fboxsep,
- alsoletter={\\,*,\&},
- morekeywords={\\AtBeginDocument,
- \\RequirePackage,
- \\PreviewEnvironment,
- \&},
- morekeywords=[2]{pspicture,
- verbatim,
- table,
- other,
- tikzpicture,
- postscript,
- preview,
- TRICKS,
- POSTRICKS,
- TIKZPICTURE,
- OTHER,
- nopreview},
- morekeywords=[3]{\\begin,
- \\pspicture,
- \\TRICKS,
- \\ENDTRICKS,
- \\endpspicture,
- \\end},
- literate=*{\{}{{\textcolor{myblue}{\{}}}{1}
- {\}}{{\textcolor{myblue}{\}}}}{1}
- {[}{{\textcolor{myblue}{[}}}{1}
- {]}{{\textcolor{myblue}{]}}}{1},
-}
-
+columns=flexible,
+frame=single,
+framerule=0pt,%
+backgroundcolor=\color{gray!10},%
+xleftmargin=\fboxsep,%
+xrightmargin=\fboxsep,
+alsoletter={\\,*,\&},
+morekeywords={\\AtBeginDocument,
+ \\RequirePackage,
+ \\PreviewEnvironment,
+ \&},
+morekeywords=[2]{pspicture,
+ verbatim,
+ table,
+ other,
+ tikzpicture,
+ postscript,
+ preview,
+ TRICKS,
+ POSTRICKS,
+ TIKZPICTURE,
+ OTHER,
+ nopreview},
+morekeywords=[3]{\\begin,
+ \\pspicture,
+ \\TRICKS,
+ \\ENDTRICKS,
+ \\endpspicture,
+ \\end},
+literate=*{\{}{{\textcolor{myblue}{\{}}}{1}
+ {\}}{{\textcolor{myblue}{\}}}}{1}
+ {[}{{\textcolor{myblue}{[}}}{1}
+ {]}{{\textcolor{myblue}{]}}}{1},
+ }
\lstset{language=mytex}
\lstdefinestyle{mystyle1}{
- basicstyle=\small\ttfamily,
- keywordstyle=\bfseries\color{red},
- keywordstyle=[2]{\color{magenta}},
- keywordstyle=[3]{\color{blue}},
- commentstyle=\color{darkgreen},
- stringstyle=\color{orange},
- identifierstyle=\ttfamily,
- showstringspaces=true,
- breaklines=true,
- tabsize=4,
- columns=fullflexible,
- keepspaces=true,
-}
-
+ basicstyle=\small\ttfamily,
+ keywordstyle=\bfseries\color{red},
+ keywordstyle=[2]{\color{magenta}},
+ keywordstyle=[3]{\color{blue}},
+ commentstyle=\color{darkgreen},
+ stringstyle=\color{orange},
+ identifierstyle=\ttfamily,
+ showstringspaces=true,
+ breaklines=true,
+ tabsize=4,
+ columns=fullflexible,
+ keepspaces=true,
+ }
+% style
\lstset{style=mystyle1}
\begin{document}
-\title{{\huge\textsf{lxtimg}}\\export tikz|pstricks environments to image format\\ \small v. 1.0}
+\title{{\Huge\textffm{LTX}\textffmw{img} \normalsize \Large\textffmw{v1.1}}\\\small\textffm{tikz|pgf|pstricks \\to image format}}
\author{Pablo Gonz\'{a}lez Luengo\\ \small \ttfamily pablgonz at yahoo dot com}
\date{\today}
\maketitle
\begin{abstract}
\noindent
-\textsf{ltximg}\footnote{Thanks to Giuseppe Matarazzo for his kind help on testing the script.} is a \textsf{Perl} script that automates the process to export \textsf{tikzpicture} or \textsf{pspicture} environments to image formats (PDF, EPS, PPM, PNG).
+\textsf{ltximg} is a \textsf{Perl} script that automates the process to extract and convert all PGF|TiKZ|Pstricks environments from input file to image formats (pdf,png,jpg,eps,ppm,svg) and source code for environments in individual files using \textsf{Ghostscript} and other software. By default search and extract environments using \hologo{pdfLaTeX}.
\end{abstract}
\tableofcontents
\section{Required Software}
-For the full operation of the script you need the following opensource programs
-(available for windows and linux), external to \textsc{ctan} repositories.
+For the full operation of the \textsf{ltximg} script you need the following opensource programs
+(available for windows and linux).
\begin{itemize}
-\item \textsf{Perl}.
+\item \textsf{Perl} (version 5.18 or higer).
-\item \textsf{Ghostscript}.
+\item \textsf{Ghostscript} (version 9.16).
-\item \textsf{pdftops} (optional, for images in EPS format).
+\item \textsf{pdftops} (optional, for images in \textsf{EPS} format).
-\item \textsf{pdftoppm} (optional, for images in PPM format).
+\item \textsf{pdftoppm} (optional, for images in \textsf{PPM} format).
-\item \textsf{ImageMagick} (optional, for conversion images).
+\item \textsf{pdf2svg} (optional, for images in \textsf{SVG} format).
\end{itemize}
\newpage
\section{Run and options}
-For \TeX Live or Mik\TeX\ users the syntax for \textsf{ltximg} script is simple:
-
+the syntax for \textsf{ltximg} script is simple:
+\noindent
+For \TeX Live users:
\begin{lstlisting}
-perl ltximg file.tex -options
+ltximg file.tex --options
+\end{lstlisting}
+For Mik\TeX\ users:
+\begin{lstlisting}
+perl ltximg file.tex --miktex --options
\end{lstlisting}
-
\begin{table}[htp]
-\caption{Options for ltximg}
+\caption{Options for \textsf{ltximg}}
\begin{tabularx}{\linewidth}{@{}>{\ttfamily} l>{\ttfamily} l >{\ttfamily}l X @{}}\\\toprule
-\emph{name} & \emph{short} & \emph{default} & \emph{description}\\\midrule
---help & --h & & display help information and exit.\\
---version & --v & & display version information and exit.\\
---license & --li & & display license information and exit.\\
---imageDir= & & images & The dir for the created images.\\
---DPI= & --d & 300 & Dots per inch for gs, pdftoppm and mogrify.\\
---IMO="..." & & & Aditional options for mogrify (need double quotes).\\
---clear & --c & & Delete all temp files.\\
---xetex & --xe & & Create all image using xelatex (tikz and pstricks).\\
---luatex & --lu & & Create all image using lualatex (tikz).\\
---latex & --la & & Create all image using latex(pstricks).\\
---useppm & --up & & Create jpg and png using mogrify and ppm\\
---usemog & --um & & Create jpg and png (transparent) using mogrify and pdf\\
---margins= & --m & 0 & Margins for pdfcrop.\\
---pdf & & & Create .pdf files using gs.\\
---ppm & & & Create .ppm files (need pdftoppm).\\
---eps & & & Create .eps files (need pdftops).\\
---jpg & & & Create .jpg files (deafult use gs).\\
---png & & & Create .png files (deafult use gs).\\
---skip= & --s & skip & Name for skip environmet in input file.\\
---other= & --o & other & Name for other export environmet.\\
---all & --a & & Create pdf/jpg/png/eps image type.\\
-\bottomrule
+\emph{short} & \emph{long} & \emph{default} & \emph{description}\\\midrule
+ -h &--help & & Display help from command line and exit.\\
+ -l &--license & & Display license information and exit.\\
+ -v &--version & 1.1 & Display version of script and exit.\\
+ -d &--dpi=<int> & 150 & The dots per inch for images.\\
+ -j &--jpg & & Create \textsf{.jpg} files (need \textsf{Ghostscript}).\\
+ -p &--png & & Create \textsf{.png}files (need \textsf{Ghostscript}).\\
+ -e &--eps & & Create \textsf{.eps} files (need \textsf{pdftops}).\\
+ -s &--svg & & Create \textsf{.svg} files (need \textsf{pdf2svg}).\\
+ -P &--ppm & & Create \textsf{.ppm} files (need \textsf{pdftoppm}).\\
+ -a &--all & & Create \textsf{.(pdf,eps,jpg,png)} images.\\
+ -c &--clear & & Delete all temp and aux files.\\
+ -o &--output & & Create a \textsf{file-out.tex} whitout \textsf{PGF|TiKZ|PST} code.\\
+ -m &--margins=<int>& 0 & Margins in bp for \textsf{pdfcrop}.\\
+ -np &--nopreview & off & Create images files whitout \textsf{preview} package.\\
+ -ns &--nosource & off & Delete all source for images files\\
+ &--miktex &-shell-escape & Use \textsf{--enable-write18} for \hologo{MiKTeX} users.\\
+ &--xetex & off & Using \hologo{XeLaTeX} for create images.\\
+ &--latex & off & Using \hologo{LaTeX} for create images.\\
+ &--luatex & off & Using \hologo{LuaLaTeX} for create images.\\
+ &--nopdf & off & Don't create a PDF image files.\\
+ &--other=<string> & other & Search \textsf{other} environment for export.\\
+ &--ignore=<string> & ignore& Skip verbatim environment.\\
+ &--imgdir=<string> & images & The folder for images.\\
+ \bottomrule
\end{tabularx}
\end{table}
+
+
\section{How it works}
-The script works in two steps, but giving the same result, a new file
-\emph{without tikzpicture} environments and a folder with the images from
-these environments.
+The script works in two steps for create image, source code and output file \emph{without PGF/TIKZ/PST} environments.
+
+
+\subsection{Environment Suports}
+
+\textsf{ltximg} export and convert this environment:
+
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{pspicture}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{pspicture*}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{postscript}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{circuitikz}%
+{}
+\end{docEnvironment}
+\end{minipage}
+
+\vspace{0.5cm}
+
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{tikzpicture}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{pgfpicture}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{ganttchart}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{forest}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\vspace{0.5cm}
+
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{tikzcd}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{circuitikz}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{dependency}%
+{}
+\end{docEnvironment}
+\end{minipage}
+\begin{minipage}[c]{0.25\columnwidth}
+\begin{docEnvironment}%
+{other}%
+{}
+\end{docEnvironment}
+\end{minipage}
+
+
\subsection{Comment and ignore}
-The first step \textsf{ltximg } script create a image dir calls \textsf{images}
-and create a copy for in file, processing is as follows, being assumed that our file is \texttt{test.tex}:
+The first step \textsf{ltximg } script create a image dir (\textsf{images/})
+and read all input file in memory, processing is as follows, being assumed that our file is \texttt{test.tex}:
\begin{enumerate}
-\item Create a copy file called test-tmp.tex and put the problematic environments (verbatim, verbatim\*, lstlisting,
- LTXexample, Verbatim, comment, alltt, minted, tcblisting, xcomment and skip) inside the:
+\item Create a copy file in memory and change problematic environments (verbatim, verbatim\*, lstlisting,
+ LTXexample, Verbatim, comment, alltt, minted, tcblisting, xcomment and ignore)
+
+\item Change problematic inline verbatim from varius package (lstlisting,LTXexample, Verbatim, comment, alltt, minted, tcblisting, etc) include line whit \%.
+\end{enumerate}
-\begin{lstlisting}
-\begin{nopreview}
-...
-\end{nopreview}
-\end{lstlisting}
-and:
+
+\subsection{Create source and images}
\begin{enumerate}
-\item If the option is latex adds the following lines to the beginning of the test-fig.tex:
+
+\item If script is call whitout \textsf{--nopreview} option (default), adds the following lines to the beginning of the test.tex in memory and save file test-fig.tex in images dir :
\begin{lstlisting}
\AtBeginDocument{
\RequirePackage[active,tightpage]{preview}
-\PreviewEnvironment{pspicture}
-\PreviewEnvironment{other}}
+\renewcommand\PreviewBbAdjust{-60pt -60pt 60pt 60pt}%
+\newenvironment{postscript}{}{}%
+\PreviewEnvironment{postscript}}%
\end{lstlisting}
-\item If options its xetex adds the following lines to the beginning of the test-fig.tex:
+\item If script is call whit \textsf{--nopreview} option, all environment code its put inside the :
\begin{lstlisting}
-\AtBeginDocument{
-\RequirePackage[xetex,active,tightpage]{preview}
-\PreviewEnvironment{tikzpicture}
-\PreviewEnvironment{pspicture}
-\PreviewEnvironment{other}}
+\begin{postscript}
+...
+\end{postscript}
\end{lstlisting}
-\item And if no option is given, adds the following lines at the beginning of the test-fig.tex. This is the default for
-lualatex and pdflatex.
+and separate in individual files (test-fig-1.tex, test-fig-2.tex, etc) in image dir and join in test-fig.tex. The postscript environment can be used to place any material to be exported if that is not supported or fails the \textsf{--other} option.
-\begin{lstlisting}
-\AtBeginDocument{
-\RequirePackage[pdftex,active,tightpage]{preview}
-\PreviewEnvironment{tikzpicture}
-\PreviewEnvironment{other}}
-\end{lstlisting}
+\item Now, the script call (pdf/lua/xe)latex in \texttt{test-fig.tex} and \textsf{pdfcrop} in
+\texttt{test-fig.pdf} and create image files.
\end{enumerate}
-\item Open test-tmp.tex and change the problematic words for verbatin in line or after \% symbol:
-
+\section{Example}
\begin{lstlisting}
-\pspicture => \TRICKS
-\endpspicture => \ENDTRICKS
-\begin{pspicture => \begin{TRICKS
-\end{pspicture => \end{TRICKS
-\begin{postscript} => \begin{POSTRICKS}
-\end{postscript} => \end{POSTRICKS}
-\begin{tikzpicture => \begin{TIKZPICTURE
-\end{tikzpicture => \end{TIKZPICTURE
-\begin{other => \begin{OTHER
-\end{other => \end{OTHER
+ltximg test.tex -e -p -j -c -o --imgdir=pics
\end{lstlisting}
+produce test-out.tex whitout PGF|TiKZ|PST environments and create "pics" dir whit all images (pdf,eps,png,jpg) and source (.tex) for all related parts using \hologo{pdfLaTeX} whit preview package and cleaning all tmp files.
-and save file called test-fig.tex then runs (pdf/lua/xe)latex in \texttt{test-fig.tex} and \textsf{pdfcrop} in
-\texttt{test-fig.pdf}.
-\end{enumerate}
-\subsection{Split and convert}
-If \textsf{ltximg} called with option \textsf{-pdf} or \textsf{-eps} or \textsf{-um} the file \texttt{test-fig.pdf}
-is splitting in \texttt{test-fig-1.pdf, test-fig-2.pdf,\ldots} and puts them into \texttt{images} dir. The invoked behind this command is:
-
+\noindent
+Suport bundling for short options:
\begin{lstlisting}
-gs -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dNOPAUSE -dBATCH -sOutputFile=imageDir/test-fig-%d.pdf \
-test-fig.pdf
+ltximg test.tex -epjco --imgdir=pics
\end{lstlisting}
-and then processes the remaining options.
-
-For example, if you use the option \textsf{-pdf -um} the command behind this is:
+\end{document}
-\begin{lstlisting}
-mogrify -define png:format=png32 -define png:compression-filter=4 -quality 100 -transparent white \
--density 300 -format png *.pdf
-\end{lstlisting}
-And if you use the option \textsf{-pdf -up} the command behind this is:
-\begin{lstlisting}
-mogrify -quality 100 -define png:format=png32 -define png:compression-filter=4 -density 300 \
--format png *.ppm
-\end{lstlisting}
+LTXimg extract and convert all PGF|TiKZ|Pstricks environments from TeX
+ source into single images files (pdf/png/eps/jpg/svg) using Ghostscript.
+ By default search and extract environments using (pdf)LaTeX.
+Environments suports by LTXimg:
-\section{Creating other images format}
-If you need to create other image formats we first need to generate the PPM format or PDF, then the procedure is simple
-using the \textsf{ImageMagick} \texttt{convert} command, command usage is so:
-\begin{lstlisting}
-mogrify -format ext *.ppm
-\end{lstlisting}
-for TIFF use
-\begin{lstlisting}
-mogrify -format tiff *.ppm
-\end{lstlisting}
+ pspicture tikzpicture pgfpicture forest ganttchart
+ tikzcd circuitikz dependency other postscript
-\end{document} \ No newline at end of file
+Options:
+\begin{tabularx}{\linewidth}{@{}>{\ttfamily} l>{\ttfamily} l >{\ttfamily}l X @{}}\\\toprule
+\emph{short} & \emph{name} & \emph{default} & \emph{description}\\\midrule
+ -h&--help & &display this help and exit
+ -l&--license & &- display license information and exit
+ -v&--version & & - display version (current 1.2) and exit
+ -d&--dpi=<int> & 150 & - the dots per inch for images
+ -j&--jpg & &- create .jpg files (need Ghostscript)
+ -p&--png & &- create .png files (need Ghostscript)
+ -e&--eps & &- create .eps files (need pdftops)
+ -s&--svg & &- create .svg files (need pdf2svg)
+ -P&--ppm & &- create .ppm files (need pdftoppm)
+ -a&--all & &- create .(pdf,eps,jpg,png) images
+ -c&--clear & &- delete all temp and aux files
+ -o&--output & &- create a file-out.tex whitout PGF|TiKZ|PST code
+ -m&--margins=<int>& &- margins in bp for pdfcrop (default 0)
+ -np&--nopreview & &- create images files whitout preview package
+ -ns&--nosource & &- delete all source for images files
+ &--miktex & &- use --enable-write18 for MikTeX users
+ &--xetex & &- using (Xe)LaTeX for create images
+ &--latex & &- using LaTeX for create images
+ &--luatex & &- using (Lua)LaTeX for create images
+ &--nopdf & &- don't create a PDF image files (default off)
+ &--other=<string> & &- search other environment (default other)
+ &--ignore=<string> & &- skip verbatim environment (default ignore)
+ &--imgdir=<string> & &- the folder for images (default images)
+ \bottomrule
+\end{tabularx}
+
+
+Example:
+* ltximg test.tex -e -p -j -c -o --imgdir=pics
+* produce test-out.tex whitout PGF|TiKZ|PST environments and create "pics"
+* dir whit all images (pdf,eps,png,jpg) and source (.tex) for all related
+* parts using (pdf)LaTeX whit preview package and cleaning all tmp files.
+* Suport bundling for short options: ltximg test.tex -epjco --imgdir=pics
+END_OF_USAGE
diff --git a/Master/texmf-dist/doc/support/ltximg/test.tex b/Master/texmf-dist/doc/support/ltximg/test.tex
deleted file mode 100644
index 32872a9ec33..00000000000
--- a/Master/texmf-dist/doc/support/ltximg/test.tex
+++ /dev/null
@@ -1,47 +0,0 @@
-\documentclass{article}
-\usepackage[cmyk]{xcolor}
-\usepackage{tikz}
-\usepackage{pstricks-add}
-\begin{document}
-Text inline \verb|\begin{pspicture*} o \begin{tikzpicture} \begin{other}|
-
-\begin{tikzpicture}
-\shadedraw [shading=ball] (0,0) circle (2cm);
-\end{tikzpicture}
-
-\begin{verbatim}
-\begin{tikzpicture}
-\shadedraw [shading=ball] (0,0) circle (2cm);
-\end{tikzpicture}
-\end{verbatim}
-
-\begin{pspicture}(-0.5,-0.5)(5,3.5)
-\psset{unit=1.0cm,algebraic=true,dimen=middle,linewidth=0.8pt}
-\pscustom[linewidth=0.7pt,linecolor=red,fillcolor=red,fillstyle=solid,opacity=0.25]{
-\parametricplot{-2.39}{-1.14}{0.52*cos(t)+3.25|0.52*sin(t)+3}
-\lineto(3.25,3)\closepath}
-\pspolygon[linewidth=0.7pt,linecolor=cyan,fillcolor=green,fillstyle=solid,opacity=0.25](0.25,0.25)(3.25,3)(4.5,0.25)
-\begin{scriptsize}
-\uput[d](0.25,0.25){\red{$A$}}
-\uput[u](3.25,3){\red{$B$}}
-\uput[d](4.5,0.25){\red{$C$}}
-\uput{7pt}[-100](3.25,3){\red{$\alpha$}}
-\end{scriptsize}
-\end{pspicture}
-
-\begin{verbatim}
-\begin{pspicture}(-0.5,-0.5)(5,3.5)
-\psset{unit=1.0cm,algebraic=true,dimen=middle,linewidth=0.8pt}
-\pscustom[linewidth=0.7pt,linecolor=red,fillcolor=red,fillstyle=solid,opacity=0.25]{
-\parametricplot{-2.39}{-1.14}{0.52*cos(t)+3.25|0.52*sin(t)+3}
-\lineto(3.25,3)\closepath}
-\pspolygon[linewidth=0.7pt,linecolor=cyan,fillcolor=blue,fillstyle=solid,opacity=0.25](0.25,0.25)(3.25,3)(4.5,0.25)
-\begin{scriptsize}
-\uput[d](0.25,0.25){\red{$A$}}
-\uput[u](3.25,3){\red{$B$}}
-\uput[d](4.5,0.25){\red{$C$}}
-\uput{7pt}[-100](3.25,3){\red{$\alpha$}}
-\end{scriptsize}
-\end{pspicture}
-\end{verbatim}
-\end{document}
diff --git a/Master/texmf-dist/scripts/ltximg/ltximg.pl b/Master/texmf-dist/scripts/ltximg/ltximg.pl
index ccb7f92fe2d..d9aefa8164a 100755
--- a/Master/texmf-dist/scripts/ltximg/ltximg.pl
+++ b/Master/texmf-dist/scripts/ltximg/ltximg.pl
@@ -1,40 +1,243 @@
-#!/usr/bin/perl
-use v5.14;
-use strict; # to be sure, that all is safe ... :-)
-use File::Path;
-use File::Copy;
-use File::Basename;
-use IO::File;
-use Getopt::Long;
-use autodie;
-
-my $tempDir = "."; # temporary directory
-my $clear = 0; # 0 or 1, clears all temporary files
-my $DPI = "300"; # value for ppm
-my $margins = "0"; # margins for pdf crop
-my $imageDir = "images"; # directorio de imágenes (images por defecto)
-my $skip = "skip"; # skip environment
-my $latex = 0; # 1->create all images using latex
-my $xetex = 0; # 1->create all images using xelatex
-my $luatex = 0; # 1->create all images using lualatex
-my $IMO = ""; # 1->Options for ImageMagick
-my $GSCMD = "gs"; # Ghostscript name
-my $other = "other"; # search other environment for export
-my $pdf = 0; # 1->create .pdf using ghostscript
-my $png = 0; # 1->create .png
-my $jpg = 0; # 1->create .jpg
-my $eps = 0; # 1->create .eps using pdftops
-my $ppm = 0; # 1->create .ppm using pdftoppm
-my $useppm = 0; # 1->create jpg/png using mogrify and ppm
-my $usemog = 0; # 1->create jpg/png using mogrify
-my $all = 0; # 1->create all images and files for type
-
-#----------------------- User part end ---------------------------
-#-----------------program identification, options and help--------
-my $program = "ltximg";
-my $ident = '$Id: ltximg v1.0, 2013-03-12 pablo $';
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' if 0;
+use v5.18;
+use File::Path; # creating/removing dirs
+use File::Copy; # copying files
+use File::Basename; # scan argument
+use IO::File; # simple IO operation
+use Getopt::Long qw(:config bundling_override); # read parameter and activate "bundling"
+use autodie; # more safe
+use Config;
+use File::Spec;
+use File::Find;
+
+#------------------------ Constantes ----------------------------------#
+my $tempDir = "."; # temporary directory
+my $other = "other"; # other environment for search
+my $imageDir = "images"; # Dir for images (images default)
+my $ignore = "ignore"; # ignore verbatim environment
+my $exacount = 1; # Counter for source images
+my $imgNo = 1; # Counter for PGF/TIKZ/PST environments
+my $nopreview = 0; # 1->create images in nopreview mode
+my $noSource = 0; # Delete TeX source for images
+my $nopdf = 0; # No create a PDF image file
+my $clear = 0; # 0 or 1, clears all temporary files
+my $DPI = "150"; # value for ppm, png, jpg
+my $margins = "0"; # margins for pdf crop
+my $latex = 0; # 1->create all images using latex
+my $xetex = 0; # 1->create all images using xelatex
+my $luatex = 0; # 1->create all images using lualatex
+my $png = 0; # 1->create .png using Ghoscript
+my $jpg = 0; # 1->create .jpg using Ghoscript
+my $eps = 0; # 1->create .eps using pdftops
+my $svg = 0; # 1->create .svg files
+my $ppm = 0; # 1->create .ppm using pdftoppm
+my $all = 0; # 1->create all images and files for type
+my $output = 0; # 1->create output file whitout PGF/PST
+my $miktex = 0; # 1->enable write 18 for miktex system
+my $Verbose = 0; # 0 or 1, logfile
+
+#------------------------------ CHANGES -------------------------------#
+# v1.2 2015-04-21 - Change mogrify to gs for image formats
+# - Create output file
+# - Rewrite source code and fix regex
+# - Add more image format
+# - Change date to iso format
+# v1.0 2013-12-01 - First public release
+#----------------------------------------------------------------------#
+
+#----------------------------- Search GS ------------------------------#
+# The next code its part of pdfcrop from TexLive 2014
+# Windows detection
+my $Win = 0;
+$Win = 1 if $^O =~ /mswin32/i;
+$Win = 1 if $^O =~ /cygwin/i;
+
+my $archname = $Config{'archname'};
+$archname = 'unknown' unless defined $Config{'archname'};
+
+# get Ghostscript command name
+$::opt_gscmd = '';
+sub find_ghostscript () {
+ return if $::opt_gscmd;
+ if ($Verbose) {
+ print "* Perl executable: $^X\n";
+ if ($] < 5.006) {
+ print "* Perl version: $]\n";
+ }
+ else {
+ printf "* Perl version: v%vd\n", $^V;
+ }
+ if (defined &ActivePerl::BUILD) {
+ printf "* Perl product: ActivePerl, build %s\n", ActivePerl::BUILD();
+ }
+ printf "* Pointer size: $Config{'ptrsize'}\n";
+ printf "* Pipe support: %s\n",
+ (defined($Config{'d_pipe'}) ? 'yes' : 'no');
+ printf "* Fork support: %s\n",
+ (defined($Config{'d_fork'}) ? 'yes' : 'no');
+ }
+ my $system = 'unix';
+ $system = "dos" if $^O =~ /dos/i;
+ $system = "os2" if $^O =~ /os2/i;
+ $system = "win" if $^O =~ /mswin32/i;
+ $system = "cygwin" if $^O =~ /cygwin/i;
+ $system = "miktex" if defined($ENV{"TEXSYSTEM"}) and
+ $ENV{"TEXSYSTEM"} =~ /miktex/i;
+ print "* OS name: $^O\n" if $Verbose;
+ print "* Arch name: $archname\n" if $Verbose;
+ print "* System: $system\n" if $Verbose;
+ my %candidates = (
+ 'unix' => [qw|gs gsc|],
+ 'dos' => [qw|gs386 gs|],
+ 'os2' => [qw|gsos2 gs|],
+ 'win' => [qw|gswin32c gs|],
+ 'cygwin' => [qw|gs gswin32c|],
+ 'miktex' => [qw|mgs gswin32c gs|]
+ );
+ if ($system eq 'win' or $system eq 'cygwin' or $system eq 'miktex') {
+ if ($archname =~ /mswin32-x64/i) {
+ my @a = ();
+ foreach my $name (@{$candidates{$system}}) {
+ push @a, 'gswin64c' if $name eq 'gswin32c';
+ push @a, $name;
+ }
+ $candidates{$system} = \@a;
+ }
+ }
+ my %exe = (
+ 'unix' => '',
+ 'dos' => '.exe',
+ 'os2' => '.exe',
+ 'win' => '.exe',
+ 'cygwin' => '.exe',
+ 'miktex' => '.exe'
+ );
+ my $candidates_ref = $candidates{$system};
+ my $exe = $Config{'_exe'};
+ $exe = $exe{$system} unless defined $exe;
+ my @path = File::Spec->path();
+ my $found = 0;
+ foreach my $candidate (@$candidates_ref) {
+ foreach my $dir (@path) {
+ my $file = File::Spec->catfile($dir, "$candidate$exe");
+ if (-x $file) {
+ $::opt_gscmd = $candidate;
+ $found = 1;
+ print "* Found ($candidate): $file\n" if $Verbose;
+ last;
+ }
+ print "* Not found ($candidate): $file\n" if $Verbose;
+ }
+ last if $found;
+ }
+ if (not $found and $Win) {
+ $found = SearchRegistry();
+ }
+ if ($found) {
+ print "* Autodetected ghostscript command: $::opt_gscmd\n" if $Verbose;
+ }
+ else {
+ $::opt_gscmd = $$candidates_ref[0];
+ print "* Default ghostscript command: $::opt_gscmd\n" if $Verbose;
+ }
+}
+
+sub SearchRegistry () {
+ my $found = 0;
+ eval 'use Win32::TieRegistry qw|KEY_READ REG_SZ|;';
+ if ($@) {
+ if ($Verbose) {
+ print "* Registry lookup for Ghostscript failed:\n";
+ my $msg = $@;
+ $msg =~ s/\s+$//;
+ foreach (split /\r?\n/, $msg) {
+ print " $_\n";
+ }
+ }
+ return $found;
+ }
+ my $open_params = {Access => KEY_READ(), Delimiter => '/'};
+ my $key_name_software = 'HKEY_LOCAL_MACHINE/SOFTWARE/';
+ my $current_key = $key_name_software;
+ my $software = new Win32::TieRegistry $current_key, $open_params;
+ if (not $software) {
+ print "* Cannot find or access registry key `$current_key'!\n"
+ if $::opt_verbose;
+ return $found;
+ }
+ print "* Search registry at `$current_key'.\n" if $Verbose;
+ my %list;
+ foreach my $key_name_gs (grep /Ghostscript/i, $software->SubKeyNames()) {
+ $current_key = "$key_name_software$key_name_gs/";
+ print "* Registry entry found: $current_key\n" if $Verbose;
+ my $key_gs = $software->Open($key_name_gs, $open_params);
+ if (not $key_gs) {
+ print "* Cannot open registry key `$current_key'!\n" if $Verbose;
+ next;
+ }
+ foreach my $key_name_version ($key_gs->SubKeyNames()) {
+ $current_key = "$key_name_software$key_name_gs/$key_name_version/";
+ print "* Registry entry found: $current_key\n" if $Verbose;
+ if (not $key_name_version =~ /^(\d+)\.(\d+)$/) {
+ print " The sub key is not a version number!\n" if $Verbose;
+ next;
+ }
+ my $version_main = $1;
+ my $version_sub = $2;
+ $current_key = "$key_name_software$key_name_gs/$key_name_version/";
+ my $key_version = $key_gs->Open($key_name_version, $open_params);
+ if (not $key_version) {
+ print "* Cannot open registry key `$current_key'!\n" if $Verbose;
+ next;
+ }
+ $key_version->FixSzNulls(1);
+ my ($value, $type) = $key_version->GetValue('GS_DLL');
+ if ($value and $type == REG_SZ()) {
+ print " GS_DLL = $value\n" if $Verbose;
+ $value =~ s|([\\/])([^\\/]+\.dll)$|$1gswin32c.exe|i;
+ my $value64 = $value;
+ $value64 =~ s/gswin32c\.exe$/gswin64c.exe/;
+ if ($archname =~ /mswin32-x64/i and -f $value64) {
+ $value = $value64;
+ }
+ if (-f $value) {
+ print "EXE found: $value\n" if $Verbose;
+ }
+ else {
+ print "EXE not found!\n" if $Verbose;
+ next;
+ }
+ my $sortkey = sprintf '%02d.%03d %s',
+ $version_main, $version_sub, $key_name_gs;
+ $list{$sortkey} = $value;
+ }
+ else {
+ print "Missing key `GS_DLL' with type `REG_SZ'!\n" if $Verbose;
+ }
+ }
+ }
+ foreach my $entry (reverse sort keys %list) {
+ $::opt_gscmd = $list{$entry};
+ print "* Found (via registry): $::opt_gscmd\n" if $Verbose;
+ $found = 1;
+ last;
+ }
+ return $found;
+}
+
+find_ghostscript();
+
+if ($Win and $::opt_gscmd =~ /\s/) {
+ $::opt_gscmd = "\"$::opt_gscmd\"";
+}
+# end GS search
+
+#-----------------Program identification, options and help ------------#
+
+my $program = "LTXimg";
+my $nv='1.1';
my $copyright = <<END_COPYRIGHT ;
-Copyright 2013-01-12 (c) Pablo Gonzalez L <pablgonz\@yahoo.com>
+2015-04-21 - Copyright (c) 2013-2015 by Pablo Gonzalez L.
END_COPYRIGHT
my $licensetxt = <<END_LICENSE ;
This program is free software; you can redistribute it and/or modify
@@ -52,74 +255,86 @@ my $licensetxt = <<END_LICENSE ;
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
END_LICENSE
-my $title = "$program $ident\n";
+my $title = "$program $nv, $copyright";
my $usage = <<"END_OF_USAGE";
-${title}Usage: $program file.tex [options]
-ltximg create a copy for TeX source whit all TiKZ|Pstricks environments
- and convert all environments into single images (pdf/png/eps/jpg).
- By default search and extract TiKZ environments using (pdf)LaTeX
- and ghostscript (gs).
+${title}
+Usage: ltximg file.tex [options]
-Options:
+LTXimg extract and convert all PGF|TiKZ|Pstricks environments from TeX
+ source into single images files (pdf/png/eps/jpg/svg) using Ghostscript.
+ By default search and extract environments using (pdf)LaTeX.
+
+Environments suports by LTXimg:
- --h|help - display this help and exit
- --v|version - display version information and exit
- --li|license - display license information and exit
- --imageDir= - the dir for the created images (default images)
- --d|DPI= - dots per inch for gs, pdftoppm and mogrify (default 300)
- --IMO="..." - aditional options for mogrify (need double quotes)
- --c|clear - delete all temp files
- --xe|xetex - create all image using xelatex (tikz and pstricks)
- --lu|luatex - create all image using lualatex (tikz)
- --la|latex - create all image using latex (pstricks)
- --up|useppm - create jpg and png using mogrify and ppm
- --um|usemog - create jpg and png (transparent) using mogrify and pdf
- --m|margins= - margins for pdfcrop (default 0)
- --pdf - create .pdf files using gs
- --ppm - create .ppm files (need pdftoppm)
- --eps - create .eps files (need pdftops)
- --jpg - create .jpg files (deafult use gs)
- --png - create .png files (deafult use gs)
- --s|skip= - name for skip environmet in input file (default skip)
- --o|other= - name for other export environmet (default other)
- --a|all - create pdf/jpg/png/eps image type
+ pspicture tikzpicture pgfpicture forest ganttchart
+ tikzcd circuitikz dependency other postscript
+Options:
+
+ -h,--help - display this help and exit
+ -l,--license - display license information and exit
+ -v,--version - display version (current $nv) and exit
+ -d,--dpi=<int> - the dots per inch for images (default $DPI)
+ -j,--jpg - create .jpg files (need Ghostscript)
+ -p,--png - create .png files (need Ghostscript)
+ -e,--eps - create .eps files (need pdftops)
+ -s,--svg - create .svg files (need pdf2svg)
+ -P,--ppm - create .ppm files (need pdftoppm)
+ -a,--all - create .(pdf,eps,jpg,png) images
+ -c,--clear - delete all temp and aux files
+ -o,--output - create a file-out.tex whitout PGF|TiKZ|PST code
+ -m,--margins=<int> - margins in bp for pdfcrop (default 0)
+ -np,--nopreview - create images files whitout preview package
+ -ns,--nosource - delete all source for images files
+ --miktex - use --enable-write18 for MikTeX users
+ --xetex - using (Xe)LaTeX for create images
+ --latex - using LaTeX for create images
+ --luatex - using (Lua)LaTeX for create images
+ --nopdf - don't create a PDF image files (default off)
+ --other=<string> - search other environment (default other)
+ --ignore=<string> - skip verbatim environment (default ignore)
+ --imgdir=<string> - the folder for images (default images)
+
+
+
Example:
-* $program test.tex --xe -eps -jpg -c
-* produce test-fig-1.pdf, test-fig-2.pdf, test-fig-3.pdf,...
-* and test-fig-1.eps, test-fig-2.eps, test-fig-3.eps,... and
-* test-fig-1.jpg, test-fig-2.jpg, test-fig-3.jpg,... for all
-* TiKZ|Pst environments in image dir using gs and (Xe)latex.
+* ltximg test.tex -e -p -j -c -o --imgdir=pics
+* produce test-out.tex whitout PGF|TiKZ|PST environments and create "pics"
+* dir whit all images (pdf,eps,png,jpg) and source (.tex) for all related
+* parts using (pdf)LaTeX whit preview package and cleaning all tmp files.
+* Suport bundling for short options: ltximg test.tex -epjco --imgdir=pics
END_OF_USAGE
# Options
-my $result = GetOptions ("imageDir=s" => \$imageDir,
- "s|skip=s" => \$skip,
- 'h|help' => \$::opt_help,
- 'v|version' => \$::opt_version,
- 'li|license' => \$::opt_license,
- 'd|DPI=i' => \$DPI,
- "tempDir=s" => \$tempDir,
- 'c|clear' => \$clear,
- "la|latex" => \$latex,
- "xe|xetex" => \$xetex,
- "lu|luatex" => \$luatex,
- "o|other=s" => \$other,
- "m|margins=s" => \$margins,
- "GSCMD=s" => \$GSCMD,
- "IMO=s" => \$IMO,
- "png" => \$png,
- "jpg" => \$jpg,
- "eps" => \$eps,
- "ppm" => \$ppm,
- "up|useppm" => \$useppm,
- "um|usemog" => \$usemog,
- "pdf" => \$pdf,
- "a|all" => \$all
- ) or die $usage;
+my $result=GetOptions (
+ 'h|help' => \$::opt_help,
+ 'v|version' => \$::opt_version,
+ 'l|license' => \$::opt_license,
+ 'd|dpi=i' => \$DPI,# numeric
+ 'm|margins=i' => \$margins,# numeric
+ 'imgdir=s' => \$imageDir, # string
+ 'ignore=s' => \$ignore, # string
+ 'other=s' => \$other, # string
+ 'c|clear' => \$clear, # flag
+ 'np|nopreview' => \$nopreview, # flag
+ 'e|eps' => \$eps, # flag
+ 'j|jpg' => \$jpg, # flag
+ 'p|png' => \$png, # flag
+ 'P|ppm' => \$ppm, # flag
+ 's|svg' => \$svg, # flag
+ 'a|all' => \$all, # flag
+ 'miktex' => \$miktex, # flag
+ 'nopdf' => \$nopdf, # flag
+ 'o|output' => \$output, # flag
+ 'xetex' => \$xetex, # flag
+ 'latex' => \$latex, # flag
+ 'luatex' => \$luatex,# flag
+ 'ns|nosource' => \$noSource, # flag
+ 'Verbose' => \$Verbose,
+) or die $usage;
# help functions
-sub errorUsage { die "Error: @_ (try --help for more information)\n"; }
+sub errorUsage { die "@_ (try ltximg --help for more information)\n"; }
# options for command line
if ($::opt_help) {
@@ -128,7 +343,6 @@ if ($::opt_help) {
}
if ($::opt_version) {
print $title;
- print $copyright;
exit(0);
}
if ($::opt_license) {
@@ -145,11 +359,12 @@ if ($xetex) {
if ($luatex) {
$luatex = 1;
}
-if ($pdf) {
- $pdf = 1;
+
+if ($nopdf) {
+ $nopdf = 1;
}
if ($eps) {
- $pdf =$eps = 1;
+ $eps = 1;
}
if ($jpg) {
$jpg = 1;
@@ -160,357 +375,649 @@ if ($png) {
if ($ppm) {
$ppm = 1;
}
-if ($^O eq 'MSWin32'){
- $GSCMD = "gswin32c";
-}
-if ($^O eq 'MSWin64'){
- $GSCMD = "gswin64c";
-}
-if ($useppm){
- $ppm = $useppm = 1;
-}
-if ($usemog){
- $pdf = $usemog = 1;
+if ($svg) {
+ $svg = 1;
}
if ($all){
- $pdf =$eps = $png = $jpg = 1;
+ $eps = $png = $jpg = 1;
}
-## Create image dir
-if (! -e $imageDir) {
- mkdir($imageDir,0744) or die "Can't create $imageDir";
+
+if ($nopreview) {
+ $nopreview= 1;
+}
+
+if ($output) {
+ $output= 1;
}
+if ($miktex) {
+ $miktex= 1;
+}
# open file
+
my $InputFilename = "";
@ARGV > 0 or errorUsage "Input filename missing";
@ARGV < 2 or errorUsage "Unknown option or too many input files";
$InputFilename = $ARGV[0];
-
-# end open file
-my @SuffixList = ( ".tex", "", ".ltx" ); # possible extensions
-my ( $name, $path, $ext ) = fileparse( $ARGV[0], @SuffixList );
-if ( $ext eq "" ) { $ext = ".tex"; } # me need the extension as well
-my $TeXfile = "$path$name$ext";
-# Define in file
-my $archivo_entrada = shift;
+#--------------------- Arreglo de la extensión ------------------------#
+my @SuffixList = ('.tex', '', '.ltx'); # posible extensión
+my ($name, $path, $ext) = fileparse($ARGV[0], @SuffixList);
+$ext = '.tex' if not $ext;
-# Read in file
-open my $ENTRADA, '<', $archivo_entrada;
-my $archivo;
-{
- local $/;
- $archivo = <$ENTRADA>;
-}
-close $ENTRADA;
-## cambiar
-$archivo =~
-s/(?<inicio>\\begin\{)(?<verb>verbatim|verbatim\*|lstlisting|LTXexample|Verbatim|comment|alltt|minted|tcblisting|xcomment|$skip) (?:\})
-/\\begin\{nopreview}
-$+{inicio}$+{verb}\}/gmxs;
-
-$archivo =~
-s/(?<fin>\\end\{)(?<verb>verbatim|verbatim\*|lstlisting|LTXexample|Verbatim|comment|alltt|minted|tcblisting|xcomment|$skip) (?:\})
-/$+{fin}$+{verb}\}
-\\end\{nopreview}/gmxs;
-# Save
-open my $SALIDA, '>', "$tempDir/$name-tmp.tex";
-print $SALIDA $archivo;
-close $SALIDA;
-
-# Add preview in preamble
+#---------------- Creamos el directorio para las imágenes -------------#
+-e $imageDir or mkdir($imageDir,0744) or die "No puedo crear $imageDir: $!\n";
-open my $INFILE,'<', "$tempDir/$name-tmp.tex";
-open my $OUTFIlE,'>',"$tempDir/$name-fig.tex";
-print $OUTFIlE "\\AtBeginDocument\{\n";
- if($xetex){
- print $OUTFIlE "\\RequirePackage\[xetex,active,tightpage\]\{preview\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{tikzpicture\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{pspicture\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{$other\}\}\n";
- }
- elsif($latex){
- print $OUTFIlE "\\RequirePackage\[active,tightpage\]\{preview\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{pspicture\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{$other\}\}\n";
- }
- else {
- print $OUTFIlE "\\RequirePackage\[pdftex,active,tightpage\]\{preview\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{tikzpicture\}\n";
- print $OUTFIlE "\\PreviewEnvironment\{$other\}\}\n";
- }
-
- while ( my $line = <$INFILE> ) {
- print $OUTFIlE $line;
- }
-close $INFILE;
-close $OUTFIlE;
-
-if ($clear) {unlink "$tempDir/$name-tmp.tex";}
-
-# Parser inline verbatim
+# Define in file
+my $archivo_entrada = shift;
-## Lectura del archivo
-open my $PARSER, '<', "$tempDir/$name-fig.tex";
-undef $/; # read al file
-my $file_PARSER = <$PARSER>;
-close $PARSER;
+# Standart line ltximg run
+print "$program $nv, $copyright";
-## Partición del documento
-my($cabeza,$cuerpo,$final) = $file_PARSER =~ m/\A (.+? ^\\begin{document}) \s* (.+?) \s* (^ \\end{document}) \s* \z/msx;
-
-## Cambios a realizar
+##---------------------------- PARTE 1 -------------------------------##
+#------------ Creamos un hash con los cambios para verbatim -----------#
my %cambios = (
+# pst/tikz set
+ '\psset' => '\PSSET',
+ '\tikzset' => '\TIKZSET',
+# pspicture
'\pspicture' => '\TRICKS',
'\endpspicture' => '\ENDTRICKS',
-
+# pspicture
'\begin{pspicture' => '\begin{TRICKS',
'\end{pspicture' => '\end{TRICKS',
-
+# postscript
'\begin{postscript}' => '\begin{POSTRICKS}',
'\end{postscript}' => '\end{POSTRICKS}',
-
- '\begin{tikzpicture' => '\begin{TIKZPICTURE',
- '\end{tikzpicture' => '\end{TIKZPICTURE',
-
- "\\begin\{$other" => '\begin{OTHER',
- "\\end\{$other" => '\end{OTHER',
+# $other
+ "\\begin\{$other" => '\begin{OTHER',
+ "\\end\{$other" => '\end{OTHER',
+# document
+ '\begin{document}' => '\begin{DOCTRICKS}',
+ '\end{document}' => '\end{DOCTRICKS}',
+# tikzpicture
+ '\begin{tikzpicture}' => '\begin{TIKZPICTURE}',
+ '\end{tikzpicture}' => '\end{TIKZPICTURE}',
+# pgfinterruptpicture
+ '\begin{pgfinterruptpicture'=> '\begin{PGFINTERRUPTPICTURE',
+ '\end{pgfinterruptpicture' => '\end{PGFINTERRUPTPICTURE',
+# pgfpicture
+ '\begin{pgfpicture}' => '\begin{PGFPICTURE}',
+ '\end{pgfpicture}' => '\end{PGFPICTURE}',
+# ganttchart
+ '\begin{ganttchart}' => '\begin{GANTTCHART}',
+ '\end{ganttchart}' => '\end{GANTTCHART}',
+# circuitikz
+ '\begin{circuitikz}' => '\begin{CIRCUITIKZ}',
+ '\end{circuitikz}' => '\end{CIRCUITIKZ}',
+# forest
+ '\begin{forest}' => '\begin{FOREST}',
+ '\end{forest}' => '\end{FOREST}',
+# tikzcd
+ '\begin{tikzcd}' => '\begin{TIKZCD}',
+ '\end{tikzcd}' => '\end{TIKZCD}',
+# dependency
+ '\begin{dependency}' => '\begin{DEPENDENCY}',
+ '\end{dependency}' => '\end{DEPENDENCY}',
);
-
-
-## Variables y constantes
+
+#------------------------ Coment inline Verbatim ----------------------#
+open my $ENTRADA, '<', "$archivo_entrada";
+my $archivo;
+{
+ local $/;
+ $archivo = <$ENTRADA>;
+}
+close $ENTRADA;
+
+# Variables y constantes
my $no_del = "\0";
my $del = $no_del;
-
-## Reglas
+
+# Reglas
my $llaves = qr/\{ .+? \} /x;
my $no_corchete = qr/(?:\[ .+? \])? /x;
my $delimitador = qr/\{ (?<del>.+?) \} /x;
-my $verb = qr/verb [*]? /ix;
+my $verb = qr/(spv|v|V)erb [*]? /ix;
my $lst = qr/lstinline (?!\*) $no_corchete /ix;
my $mint = qr/mint (?!\*) $no_corchete $llaves /ix;
-my $marca = qr/\\ (?:$verb | $lst | $mint) (\S) .+? \g{-1} /x;
+my $marca = qr/\\ (?:$verb | $lst | $mint ) (\S) .+? \g{-1} /x;
my $comentario = qr/^ \s* \%+ .+? $ /mx;
my $definedel = qr/\\ (?: DefineShortVerb | lstMakeShortInline ) $no_corchete $delimitador /ix;
my $indefinedel = qr/\\ (?: UndefineShortVerb | lstDeleteShortInline) $llaves /ix;
+
+while ($archivo =~
+ / $marca
+ | $comentario
+ | $definedel
+ | $indefinedel
+ | $del .+? $del # delimitado
+ /pgmx) {
+ my($pos_inicial, $pos_final) = ($-[0], $+[0]); # posiciones
+ my $encontrado = ${^MATCH}; # lo encontrado
-# Changes
-
-while ($cuerpo =~
- / $marca
- | $comentario
- | $definedel
- | $indefinedel
- | $del .+? $del # delimitado
- /gimx) {
-
- my($pos_inicial, $pos_final) = ($-[0], $+[0]); # posiciones
- my $encontrado = ${^MATCH}; # lo encontrado
-
- given ($encontrado) {
- when (/$definedel/) { # definimos delimitador
- $del = $+{del};
- $del = "\Q$+{del}" if substr($del,0,1) ne '\\'; # es necesario "escapar" el delimitador
- }
- when (/$indefinedel/) { # indefinimos delimitador
- $del = $no_del;
+ if ($encontrado =~ /$definedel/){ # definimos delimitador
+ $del = $+{del};
+ $del = "\Q$+{del}" if substr($del,0,1) ne '\\'; # es necesario "escapar" el delimitador
+ }
+ elsif($encontrado =~ /$indefinedel/) { # indefinimos delimitador
+ $del = $no_del;
}
- default { # Aquí se hacen los cambios
- while (my($busco, $cambio) = each %cambios) {
-
- $encontrado =~ s/\Q$busco\E/$cambio/g; # es necesario escapar $busco, ya que contiene caracteres extraños
- }
-
- substr $cuerpo, $pos_inicial, $pos_final-$pos_inicial, $encontrado; # insertamos los nuevos cambios
+ else { # aquí se hacen los cambios
+ while (my($busco, $cambio) = each %cambios) {
+ $encontrado =~ s/\Q$busco\E/$cambio/g; # es necesario escapar $busco
+ }
+ substr $archivo, $pos_inicial, $pos_final-$pos_inicial, $encontrado; # insertamos los nuevos cambios
- pos($cuerpo)= $pos_inicial + length $encontrado; # reposicionamos la siguiente búsqueda
+ pos($archivo)= $pos_inicial + length $encontrado; # re posicionamos la siguiente búsqueda
}
- }
}
-
-# Write
-open my $OUTPARSER, '>', "$tempDir/$name-fig.tex";
-print $OUTPARSER "$cabeza\n$cuerpo\n$final\n";
-close $OUTPARSER;
+# Constantes
+my $BP = '\\\\begin{postscript}';
+my $EP = '\\\\end{postscript}';
+my $BPL = '\begin{postscript}';
+my $EPL = '\end{postscript}';
+my $sipgf = 'pgfpicture';
+my $nopgf = 'pgfinterruptpicture';
+my $graphics = "graphic=\{\[scale=1\]$imageDir/$name-fig";
-# Compiling files...
+# directorio en el cual están las imágenes
+my $dir = "$tempDir/$imageDir";
-# Using LaTeX
+#--------------------- Coment Verbatim environment --------------------#
-if($latex){
- print "Compiled using LaTeX\n";
- system("latex -interaction=batchmode $tempDir/$name-fig.tex");
- system("dvips -q -Ppdf $tempDir/$name-fig.dvi");
- system("ps2pdf -dPDFSETTINGS=\/prepress $tempDir/$name-fig.ps $tempDir/$name-fig.pdf");
-if ($clear) {
- unlink "$tempDir/$name-fig.dvi";
- unlink "$tempDir/$name-fig.ps";
- unlink "$tempDir/$name-fig.log";
- unlink "$tempDir/$name-fig.aux";
- unlink "$tempDir/$name-fig.tex";
- }
- }
-
-# Using XeLaTeX
+my @lineas = split /\n/, $archivo;
-elsif($xetex){
- print "Compiled using (Xe)LaTeX\n";
- system("xelatex -interaction=batchmode $tempDir/$name-fig.tex");
-if ($clear) {
- unlink "$tempDir/$name-fig.log";
- unlink "$tempDir/$name-fig.aux";
- unlink "$tempDir/$name-fig.tex";
- }
- }
-
-# Using LuaLaTeX
+# Verbatim environments
+my $ENTORNO = qr/(?: (v|V)erbatim\*?| PSTexample | LTXexample| $ignore\*? | PSTcode | tcblisting\*? | spverbatim | minted | lstlisting | alltt | comment\*? | xcomment)/xi;
-elsif($luatex){
- print "Compiled using (lua)LaTeX\n";
- system("lualatex -interaction=batchmode $tempDir/$name-fig.tex");
-if ($clear) {
- unlink "$tempDir/$name-fig.log";
- unlink "$tempDir/$name-fig.aux";
- unlink "$tempDir/$name-fig.tex";
- }
- }
+# postscript environment
+my $POSTSCRIPT = qr/(?: postscript)/xi;
-# Using pdfLaTeX (default)
-
-else{
- print "Compiled using (pdf)LaTeX\n";
- system("pdflatex -interaction=batchmode $tempDir/$name-fig.tex");
-if ($clear) {
- unlink "$tempDir/$name-fig.log";
- unlink "$tempDir/$name-fig.aux";
- unlink "$tempDir/$name-fig.tex";
- }
- }
-
-# Croping
+# tikzpicture environment
+my $TIKZENV = qr/(?: tikzpicture)/xi;
+#
+my $DEL;
+
+# tcbverb verbatim
+my $tcbverb = qr/\\(?:tcboxverb|myverb)/;
+my $arg_brac = qr/(?:\[.+?\])?/;
+my $arg_curl = qr/\{(.+)\}/;
+
+# coment verbatim environment
+for (@lineas) {
+ if (/\\begin\{($ENTORNO)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ }
+}
+# coment tcolorbox inline
+for (@lineas) {
+ if (m/$tcbverb$arg_brac$arg_curl/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ } # close
+ }
+# remove postscript from hash
+delete @cambios{'\begin{postscript}','\end{postscript}'};
+# coment in postscript environment
+for (@lineas) {
+ if (/\\begin\{($POSTSCRIPT)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ } # close postcript environment
+}
+# remove tikzpicture from hash
+delete @cambios{'\begin{tikzpicture}','\end{tikzpicture}'};
+# coment in tikzpicture environment
+for (@lineas) {
+ if (/\\begin\{($TIKZENV)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ } # close TIKZ environment
+}
+
+undef %cambios; # erase hash
+
+#------------- Convert ALL into Postscript environments ---------------#
+
+$archivo = join("\n", @lineas);
+## Partición del documento
+
+my($cabeza,$cuerpo,$final) = $archivo =~ m/\A (.+?) (\\begin{document} .+?)(\\end{document}.*)\z/msx;
+
+# \pspicture to \begin{pspicture}
+$cuerpo =~ s/\\pspicture(\*)?(.+?)\\endpspicture/\\begin{pspicture$1}$2\\end{pspicture$1}/gmsx;
+
+# pspicture to Postscript
+$cuerpo =~ s/
+ (
+ (?:\\psset\{[^\}]+\}.*?)?
+ (?:\\begin\{pspicture(\*)?\})
+ .*?
+ (?:\\end\{pspicture(\*)?\})
+ )
+ /$BPL\n$1\n$EPL/gmsx;
+
+# pgfpicture to Postscript
+$cuerpo =~ s/
+ (
+ \\begin{$sipgf}
+ .*?
+ (
+ \\begin{$nopgf}
+ .+?
+ \\end{$nopgf}
+ .*?
+ )*?
+ \\end{$sipgf}
+ )
+ /$BPL\n$1\n$EPL/gmsx;
+
+# tikz to Postscript
+$cuerpo =~ s/
+ (
+ (?:\\tikzset(\{(?:\{.*?\}|[^\{])*\}).*?)? # si está lo guardo
+ (?:\\begin\{tikzpicture\}) # aquí comienza la búsqueda
+ .*? # guardo el contenido en $1
+ (?:\\end\{tikzpicture\}) # termina la búsqueda
+ ) # cierra $1
+ /$BPL\n$1\n$EPL/gmsx;
+
+# rest to PostScript
+my $export = qr/(forest|ganttchart|tikzcd|circuitikz|dependency|$other\*?)/x;
+
+$cuerpo =~ s/(\\begin\{($export)\} (.*?) \\end\{\g{-2}\})/$BPL\n$1\n$EPL/gmsx;
+
+#-------------------------- Reverse changes ---------------------------#
+$archivo = "$cabeza$cuerpo$final";
+my %cambios = (
+# pst/tikz set
+ '\PSSET' => '\psset',
+ '\TIKZSET' => '\tikzset',
+# pspicture
+ '\TRICKS' => '\pspicture',
+ '\ENDTRICKS' => '\endpspicture',
+# pspicture
+ '\begin{TRICKS' => '\begin{pspicture',
+ '\end{TRICKS' => '\end{pspicture',
+# $other
+ '\begin{OTHER' => "\\begin\{$other",
+ '\end{OTHER' => "\\end\{$other",
+# document
+ '\begin{DOCTRICKS}' => '\begin{document}',
+ '\end{DOCTRICKS}' => '\end{document}',
+# tikzpicture
+ '\begin{TIKZPICTURE}' => '\begin{tikzpicture}',
+ '\end{TIKZPICTURE}' => '\end{tikzpicture}',
+# pgfinterruptpicture
+ '\begin{PGFINTERRUPTPICTURE'=> '\begin{pgfinterruptpicture',
+ '\end{PGFINTERRUPTPICTURE' => '\end{pgfinterruptpicture',
+# pgfpicture
+ '\begin{PGFPICTURE}' => '\begin{pgfpicture}',
+ '\end{PGFPICTURE}' => '\end{pgfpicture}',
+# ganttchart
+ '\begin{GANTTCHART}' => '\begin{ganttchart}',
+ '\end{GANTTCHART}' => '\end{ganttchart}',
+# circuitikz
+ '\begin{CIRCUITIKZ}' => '\begin{circuitikz}',
+ '\end{CIRCUITIKZ}' => '\end{circuitikz}',
+# forest
+ '\begin{FOREST}' => '\begin{forest}',
+ '\end{FOREST}' => '\end{forest}',
+# tikzcd
+ '\begin{TIKZCD}' => '\begin{tikzcd}',
+ '\end{TIKZCD}' => '\end{tikzcd}',
+# dependency
+ '\begin{DEPENDENCY}' => '\begin{dependency}',
+ '\end{DEPENDENCY}' => '\end{dependency}',
+);
-print "Done, $name-fig.pdf need croping, using pdfcrop whit margin $margins\n";
-system("pdfcrop --margins $margins $tempDir/$name-fig.pdf $tempDir/$name-fig.pdf");
+#-------------------------- Back Postscript ---------------------------#
-# Gs for split file
+my @lineas = split /\n/, $archivo;
+# reverse in postscript environment
+for (@lineas) {
+ if (/\\begin\{($POSTSCRIPT)(?{ $DEL = "\Q$^N" })\}/ .. /\\end\{$DEL\}/) {
+ while (my($busco, $cambio) = each %cambios) {
+ s/\Q$busco\E/$cambio/g;
+ }
+ } # close postscript environment changes
+}
-if ($pdf) {
-print "Create pdf figs in $imageDir dir using Ghostscript \($GSCMD\)\n";
-system("$GSCMD -q -sDEVICE=pdfwrite -dPDFSETTINGS=\/prepress -dNOPAUSE -dBATCH -sOutputFile=$imageDir/$name-fig-%d.pdf $tempDir/$name-fig.pdf");
+# join changes
+$archivo = join("\n", @lineas);
-# Delete last pdf (bug from gs)
+#--------------- Extract source code for PST/PGF/TIKZ -----------------#
+# Dividir el archivo
+my($cabeza,$cuerpo,$final) = $archivo =~ m/\A (.+?) (\\begin{document} .+?)(\\end{document}.*)\z/msx;
-my $i = 1;
-while (-e "$imageDir/$name-fig-${i}.pdf") { # if exisit search
- $i++; # next
-} # search end
+# Poner el atributo añadido a PostScript
+while ($cuerpo =~ /\\begin\{postscript\}/gsm) {
-$i--; # back the last
+ my $corchetes = $1;
+ my($pos_inicial, $pos_final) = ($-[1], $+[1]); # posición donde están los corchetes
-unlink "$imageDir/$name-fig-${i}.pdf";
+ if (not $corchetes) {
+ $pos_inicial = $pos_final = $+[0]; # si no hay corchetes, nos ponemos al final de \begin
+ }
+ if (not $corchetes or $corchetes =~ /\[\s*\]/) { # si no hay corchetes, o están vacíos,
+ $corchetes = "[$graphics-$exacount}]"; # ponemos los nuestros
+ }
+ substr($cuerpo, $pos_inicial, $pos_final - $pos_inicial) = $corchetes;
+ pos($cuerpo) = $pos_inicial + length $corchetes; # reposicionamos la búsqueda de la exp. reg.
+}
+continue {
+ $exacount++;
+}
+# Delte source files
+if (-e "$imageDir/$name-fig-1$ext") {
+unlink <"$imageDir/$name-fig-*$ext">;
+}
+#---------------------- Extract source code in images -----------------#
+while ($cuerpo =~ /$BP\[.+?(?<img_src_name>$imageDir\/.+?-\d+)\}\](?<code>.+?)(?=$EP)/gsm) {
+ open my $SALIDA, '>', "$+{'img_src_name'}$ext";
+ print $SALIDA <<"EOC";
+$cabeza\\pagestyle{empty}\n\\begin{document}$+{'code'}\\end{document}
+EOC
+close $SALIDA;
+}
+#--------------- Create a one file whit all figs file -----------------#
+if ($nopreview) {
+if (-e "$imageDir/$name-fig-1$ext") {
+# 1- Leer los source files
+my @pstexafiles = glob("$imageDir/$name-fig-*$ext");
+
+# 2- Ordenar según el índice y extención
+@pstexafiles =
+ map { $_->[1] }
+ sort { $a->[0] <=> $b->[0] }
+ map { [ ($_ =~ /(\d+$ext)/), $_ ] }
+ @pstexafiles;
+
+# 3- Bucle para leer las secciones
+my @almacen;
+for my $exafile (@pstexafiles) {
+
+ # 3.1- Leer el archivo
+ open my $FH, '<', $exafile; #
+ my $tex = join q{}, <$FH>; #
+ close $FH;
+
+ # 3.2- Extraer la parte que nos interesa
+ my($pedazo) = $tex =~ m/\\begin\{document\}\s*(.+?)\s*\\end\{document\}/sm;
+
+ # 3.3- Almacenamos, si hemos encontrado algo
+ push @almacen, $pedazo if $pedazo;
}
+# 4- Salida
-# Fix pdftops error message in windows
+open my $SALIDA, '>', "$tempDir/$name-fig$ext";
+print $SALIDA "$cabeza\\pagestyle{empty}\n\\begin\{document\}\n";
-if ($^O eq 'MSWin32' || $^O eq 'MSWin64'){
+my $fig = 1;
+for my $item (@almacen) {
+ print $SALIDA $item;
+ print $SALIDA "\n%% fig $fig\n";
+ print $SALIDA "\\newpage\n";
+ $fig++;
+}
+
+print $SALIDA '\end{document}';
+close $SALIDA;
+ } # close join files
+} # close $nopreview
+else {
+my $opcion = $xetex ? 'xetex,'
+ : $latex ? ''
+ : 'pdftex,'
+ ;
+
+my $preview = <<"EXTRA";
+\\AtBeginDocument\{%
+\\RequirePackage\[${opcion}active,tightpage\]\{preview\}%
+\\renewcommand\\PreviewBbAdjust\{-60pt -60pt 60pt 60pt\}%
+\\newenvironment\{postscript\}\{\}\{\}%
+\\PreviewEnvironment\{postscript\}\}%
+EXTRA
+ # write
+ open my $SALIDA, '>', "$tempDir/$name-fig$ext";
+ print $SALIDA $preview . $archivo;
+ close $SALIDA;
+}
+
+#---------------------- Create images files ---------------------------#
+# Define compilers
+my $compile = $xetex ? 'xelatex'
+ : $luatex ? 'lualatex'
+ : $latex ? 'latex'
+ : 'pdftex'
+ ;
+my $opt_compile = $miktex ? '--enable-write18 --interaction=batchmode'
+ : '--shell-escape --interaction=batchmode'
+ ;
+
+# Option for gs
+my $opt_gspdf='-q -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress';
+my $opt_gspng="-q -dSAFER -sDEVICE=pngalpha -r$DPI";
+my $opt_gsjpg="-q -dSAFER -sDEVICE=jpeg -r$DPI -dJPEGQ=100 -dGraphicsAlphaBits=4 -dTextAlphaBits=4";
+
+# Option for pdfcrop
+my $opt_crop= $xetex ? "--xetex --margins $margins"
+ : $luatex ? "--luatex --margins $margins"
+ : $latex ? "--margins $margins"
+ : "--pdftex --margins $margins"
+ ;
+# Fix pdftops error message in windows
+if ($^O eq 'MSWin32' or $^O eq 'MSWin64'){
open my $ppmconf, '>', "$tempDir/xpd";
print $ppmconf <<'EOH';
errQuiet yes
EOH
close $ppmconf;
}
-
-# Create eps files using pdftops
-
-if ($eps) {
-print "Create eps figs in $imageDir dir using pdftops\n";
-# Search pdf in $imageDir
- for my $image_pdf (<$imageDir/*.pdf>) {
-
-if ($^O eq 'MSWin32' || $^O eq 'MSWin64'){
- system("pdftops -cfg $tempDir/xpd -q -level3 -eps $image_pdf");
- }
+#-------------------------- Compiling image file ----------------------#
+if($nopreview){
+ print "Create $name-fig.pdf in $imageDir dir whit all PGF/TIKZ/PST using $compile\n";
+ }
else{
- system("pdftops -level3 -eps $image_pdf");
- }
- }
- }
-
-# Create ppm files and renamig files
-
-if($ppm){
-print "Create ppm figs in $imageDir dir using pdftoppm\n";
-if ($^O eq 'MSWin32' || $^O eq 'MSWin64'){
- system("pdftoppm -cfg $tempDir/xpd -q -r $DPI $tempDir/$name-fig.pdf $imageDir/$name-fig");
+ print "Create $name-fig.pdf in $imageDir dir whit all PGF/TIKZ/PST using $compile and preview package\n";
+ }
+
+# Run TeX mode
+system("$compile $opt_compile -output-directory=$imageDir $tempDir/$name-fig$ext");
+if($latex){
+ system("dvips -q -Ppdf -o $imageDir/$name-fig.ps $imageDir/$name-fig.dvi");
+ system("ps2pdf -dPDFSETTINGS=/prepress $imageDir/$name-fig.ps $imageDir/$name-fig.pdf");
+ }
+print "The file $imageDir/$name-fig.pdf need a cropping using pdfcrop whit options: $opt_crop\n";
+system("pdfcrop $opt_crop $imageDir/$name-fig.pdf $imageDir/$name-fig.pdf");
+
+##-------------------------- Create image formats ----------------------#
+
+opendir(my $DIR, $imageDir);
+my @figs = sort readdir $DIR;
+closedir $DIR;
+for my $fig (@figs) {
+if ($fig =~ /(?<fig>$name-fig-)(?<num>\d+)$ext/) {
+print "Create $imageDir/$name-fig-$+{num} from $name$ext\r";
+# PDF format
+if (!$nopdf) {
+system("$::opt_gscmd $opt_gspdf -o $imageDir/$name-fig-%1d.pdf $imageDir/$name-fig.pdf");
+}
+# PNG format
+if ($png) {
+system("$::opt_gscmd $opt_gspng -o $imageDir/$name-fig-%1d.png $imageDir/$name-fig.pdf");
}
-else{
- system("pdftoppm -r $DPI $tempDir/$name-fig.pdf $imageDir/$name-fig");
+# JPEG format
+if ($jpg) {
+system("$::opt_gscmd $opt_gsjpg -o $imageDir/$name-fig-%1d.jpg $imageDir/$name-fig.pdf");
+ }
+
+# SVG format pdf2svg
+if ($svg) {
+ system("pdf2svg $imageDir/$name-fig.pdf $imageDir/$+{fig}%1d.svg all");
+ }
+# EPS format
+if ($eps) {
+ if ($^O eq 'MSWin32' or $^O eq 'MSWin64'){
+ system("pdftops -cfg $tempDir/xpd -q -eps -f $+{num} -l $+{num} $imageDir/$name-fig.pdf $imageDir/$+{fig}$+{num}.eps");
+ }else{
+ system("pdftops -q -eps -f $+{num} -l $+{num} $imageDir/$name-fig.pdf $imageDir/$+{fig}$+{num}.eps");
+ }
+ } # close EPS
+# PPM format
+if ($ppm) {
+ if ($^O eq 'MSWin32' or $^O eq 'MSWin64'){
+ system("pdftoppm -cfg $tempDir/xpd -q -r $DPI -f $+{num} -l $+{num} $imageDir/$name-fig.pdf $imageDir/$+{fig}$+{num}");
}
-
-# Renaming .ppm (only need in windows)
-
-if ($^O eq 'MSWin32' || $^O eq 'MSWin64'){
-my $dren = "$tempDir/$imageDir";
-my $fichero = '';
-my $ppmren = '';
-my $renNo = 1;
-if(opendir(DIR,$dren)){
-foreach (readdir DIR){
- $fichero = $_;
- if ( $fichero =~ /($name-fig-)(\d+|\d+[-]\d+).ppm/) {
- my $renNo = int($2);
- my $newname="$1$renNo.ppm";
- $ppmren = rename("$dren/$fichero","$dren/$newname");
- }
- }
+ else{
+ system("pdftoppm -q -r $DPI -f $+{num} -l $+{num} $imageDir/$name-fig.pdf $imageDir/$+{fig}$+{num}");
}
-closedir DIR;
- }
- }
+ } # close PPM
+ } # close if ($fig =
+} # close for
-# Change dir and create png/jpg formats using mogrify and ppm
+## Renaming PPM
+if ($ppm) {
+if (opendir(DIR,$dir)) { # abro el directorio
+ while (my $oldname = readdir DIR) { # lo recorro
+ # el nuevo nombre es fruto de una sustitución
+ my $newname = $oldname =~ s/^($name-(fig|exa)-\d+)(-\d+).ppm$/$1 . ".ppm"/re;
+
+ if ($oldname ne $newname) { # comprobación
+ rename("$dir/$oldname", "$dir/$newname"); # renombro
+ }
+ }
+ closedir DIR;
+ } # close rename ppm
+} # close ppm
+
+#------- Creating output file whitout PGF/PST/TIKZ code ---------------#
+if ($output) {
+print "Create file $name-out$ext whitout PGF/PST/TIKZ code\n";
+
+#----------------- Convert Postscript to includegraphics --------------#
+my $grap="\\includegraphics[scale=1]{$name-fig-";
+my $close = '}';
+my $IMGno = 1;
+
+$cuerpo =~ s/$BP.+?$EP/$grap@{[$IMGno++]}$close/msg;
+
+#------------------------ Clean output file --------------------------#
+# append postscript to hash
+$cambios{'\begin{POSTRICKS}'} = '\begin{postscript}';
+$cambios{'\end{POSTRICKS}'} = '\end{postscript}';
+
+# Constantes
+my $BEGINDOC = quotemeta('\begin{document}');
+my $USEPACK = quotemeta('\usepackage');
+my $REQPACK = quotemeta('\usepackage');
+my $GRAPHICX = quotemeta('{graphicx}');
+
+# Exp. Reg.
+my $CORCHETES = qr/\[ [^]]*? \]/x;
+my $PALABRAS = qr/\b (?: pst-\w+ | pstricks (?: -add )? | psfrag |psgo |vaucanson-g| auto-pst-pdf | graphicx )/x;
+my $FAMILIA = qr/\{ \s* $PALABRAS (?: \s* [,] \s* $PALABRAS )* \s* \}/x;
+
+# comentar
+$cabeza =~ s/ ^ ($USEPACK $CORCHETES $GRAPHICX) /%$1/msxg;
+
+# eliminar líneas enteras
+$cabeza =~ s/ ^ $USEPACK (?: $CORCHETES )? $FAMILIA \n//msxg;
+
+# eliminar palabras sueltas
+$cabeza =~ s/ (?: ^ $USEPACK \{ | \G) [^}]*? \K (,?) \s* $PALABRAS (\s*) (,?) /$1 and $3 ? ',' : $1 ? $2 : ''/gemsx;
+
+# Añadir
+$cabeza .= <<"EXTRA";
+\\usepackage{graphicx}
+\\graphicspath{{$imageDir/}}
+\\usepackage{grfext}
+\\PrependGraphicsExtensions*{.pdf}
+EXTRA
+
+# Clear PST content in preamble
+$cabeza =~ s/\\usepackage\{\}/% delete/gmsx;
+$cabeza =~ s/\\psset\{.+?\}/% \\psset delete/gmsx;
+$cabeza =~ s/\\SpecialCoor/% \\SpecialCoor/gmsx;
+
+# Recorremos el archivo y realizamos los cambios
+while (my($busco, $cambio) = each %cambios) {
+ $cabeza =~ s/\Q$busco\E/$cambio/g;
+ $cuerpo =~ s/\Q$busco\E/$cambio/g;
+ }
+
+# write
+open my $SALIDA, '>', "$tempDir/$name-out$ext";
+print $SALIDA "$cabeza$cuerpo$final";
+close $SALIDA;
-if($usemog){
-chdir ($imageDir) or die "$imageDir not exist\n";
-if ($png) {
-print "Create png transparent in $imageDir dir using mogrify and pdf\n";
-system("mogrify $IMO -define png:format=png32 -define png:compression-filter=4 -quality 100 -transparent white -density $DPI -format png \*\.pdf");
- }
-if ($jpg) {
-print "Create jpg figs in $imageDir dir using mogrify and pdf\n";
-system("mogrify $IMO -quality 100 -density $DPI -format jpg \*\.pdf");
+# compile output file
+
+if ($xetex){
+ system("xelatex $opt_compile $tempDir/$name-out$ext");
+ } # xetex
+elsif($luatex){
+ system("lualatex $opt_compile $tempDir/$name-out$ext");
+ } # luatex
+else{
+ system("pdflatex $opt_compile $tempDir/$name-out$ext");
+ } # pdftex
+
+}# close output file
+
+#--------------------------------- Clean ------------------------------#
+if ($clear) {
+my @del_aux_tex;
+find(\&del_aux_tex, $tempDir);
+sub del_aux_tex{
+my $auximgfile = $_;
+# search .(aux|log)
+if(-f $auximgfile && $auximgfile =~ /$name-out\.(aux|log)$/){
+push @del_aux_tex, $File::Find::name;
+ }
+if(-f $auximgfile && $auximgfile =~ /$name-fig$ext/){
+push @del_aux_tex, $File::Find::name;
}
}
-elsif($useppm){
-chdir ($imageDir) or die "$imageDir not exist\n";
-if ($png) {
-print "Create png figs in $imageDir dir using mogrify and ppm\n";
-system("mogrify $IMO -quality 100 -define png:format=png32 -define png:compression-filter=4 -density $DPI -format png \*\.ppm");
- }
-if ($jpg) {
-print "Create jpg figs in $imageDir dir using mogrify and ppm\n";
-system("mogrify $IMO -quality 100 -density $DPI -format jpg \*\.ppm");
+unlink @del_aux_tex;
+} # close clear in $tempDir
+
+if ($clear) {
+my @del_tmp;
+find(\&del_tmp, $imageDir);
+sub del_tmp{
+my $auximgfile = $_;
+# search .(aux|log)
+if(-f $auximgfile && $auximgfile =~ /$name-fig\.(aux|dvi|log|ps|pdf)/){
+push @del_tmp, $File::Find::name;
}
}
-else{
-# Create png using gs (default)
+unlink @del_tmp;
+} # close clear $name-fig.tex
-if ($png) {
-print "Create png figs in $imageDir dir using Ghostscript \($GSCMD\)\n";
-system("$GSCMD -q -sDEVICE=png16m -r$DPI -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dNOPAUSE -dBATCH -sOutputFile=$imageDir/$name-fig-%d.png $tempDir/$name-fig.pdf");
- }
+# Clear source files
+if ($noSource) {
+unlink <"$imageDir/$name-fig-*$ext">;
+}# end source clear
-if ($jpg) {
-print "Create jpg figs in $imageDir dir using Ghostscript \($GSCMD\)\n";
-system("$GSCMD -q -sDEVICE=jpeg -r$DPI -dJPEGQ=100 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dNOPAUSE -dBATCH -sOutputFile=$imageDir/$name-fig-%d.jpg $tempDir/$name-fig.pdf");
- }
- }
+if ($output) {
+print "Finish, LTXimg create $name-out$ext and put all figures in $imageDir dir\n";
+}else{
+print "Finish, LTXimg create all figures in $imageDir dir\n";
+}
+if ($^O eq 'MSWin32' or $^O eq 'MSWin64'){
+unlink "$tempDir/xpd";
+ }
-print "Finish, all figures are in $imageDir dir\n";
-
__END__