texlive[47177] Master/texmf-dist: xsavebox (29mar18)

commits+karl at tug.org commits+karl at tug.org
Thu Mar 29 23:45:32 CEST 2018


Revision: 47177
          http://tug.org/svn/texlive?view=revision&revision=47177
Author:   karl
Date:     2018-03-29 23:45:32 +0200 (Thu, 29 Mar 2018)
Log Message:
-----------
xsavebox (29mar18)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/xsavebox/ChangeLog
    trunk/Master/texmf-dist/doc/latex/xsavebox/xsavebox.pdf
    trunk/Master/texmf-dist/source/latex/xsavebox/xsavebox.tex
    trunk/Master/texmf-dist/tex/latex/xsavebox/xsavebox.sty

Modified: trunk/Master/texmf-dist/doc/latex/xsavebox/ChangeLog
===================================================================
--- trunk/Master/texmf-dist/doc/latex/xsavebox/ChangeLog	2018-03-29 21:45:19 UTC (rev 47176)
+++ trunk/Master/texmf-dist/doc/latex/xsavebox/ChangeLog	2018-03-29 21:45:32 UTC (rev 47177)
@@ -1,3 +1,7 @@
+2018-03-29
+	* v0.10
+	* fix: preventing creation of unused XObjects; doc updated
+
 2018-01-16
 	* v0.9
 	* fix: README.md did not render correctly on CTAN

Modified: trunk/Master/texmf-dist/doc/latex/xsavebox/xsavebox.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/xsavebox/xsavebox.tex
===================================================================
--- trunk/Master/texmf-dist/source/latex/xsavebox/xsavebox.tex	2018-03-29 21:45:19 UTC (rev 47176)
+++ trunk/Master/texmf-dist/source/latex/xsavebox/xsavebox.tex	2018-03-29 21:45:32 UTC (rev 47177)
@@ -110,7 +110,7 @@
 \vspace{-1\baselineskip}
 \hrulefill\\[-1\baselineskip]
 
-The main difference of these commands as compared to their standard \LaTeX{} counterparts without the leading `\verb+x+' is the way of naming boxes. The label \verb+<xsbox name>+ is an identifier that may be composed of arbitrary non-active characters, including spaces and numbers. A command for declaring a box register \verb+<xsbox name>+ does not exist.
+As for usage, the main difference of these commands as compared to their standard \LaTeX{} counterparts without the leading `\verb+x+' is the way of naming boxes. The label \verb+<xsbox name>+ is an identifier that may be composed of arbitrary non-active characters, such as letters, numbers, spaces, punctuation marks. A command for declaring a box register does not exist; \verb+<xsbox name>+ it is created upon using above-listed commands and environments. Also, an existing \verb+<xsbox name>+ can be re-used, which simply overwrites its old with new content. The package keeps track of box usage; the content of a box is only written to the output file if it is referenced at least once later in the document.
 
 The \verb+[<width>]+ and \verb+[<position>]+ options have the same meaning as with \verb+\savebox+ and \verb+\makebox+. As usual, the additional length commands
 \begin{Verbatim}
@@ -129,7 +129,7 @@
 \begin{Verbatim}
   \xsbox{image for frequent use}{\includegraphics{example}}  
 \end{Verbatim}
-is useful only in the \LaTeX{} $\rightarrow$ \verb+dvips+ $\rightarrow$ \verb+ps2pdf+ work-flow, as all other engines and back-ends already take care of preventing multiple graphics file inclusion.
+is particularly useful in the \LaTeX{} $\rightarrow$ \verb+dvips+ $\rightarrow$ \verb+ps2pdf+ work-flow. Although the other engines and back-ends already take care of preventing multiple graphics file inclusion, a noticeable reduction of compilation time will be achieved in general.
 
 Verbatim content can only be saved using the `\verb+xlrbox[*]+' environment.
 

Modified: trunk/Master/texmf-dist/tex/latex/xsavebox/xsavebox.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/xsavebox/xsavebox.sty	2018-03-29 21:45:19 UTC (rev 47176)
+++ trunk/Master/texmf-dist/tex/latex/xsavebox/xsavebox.sty	2018-03-29 21:45:32 UTC (rev 47177)
@@ -49,8 +49,8 @@
 \RequirePackage{pdfbase} %everything with `pbs_' prefix
 \RequirePackage{l3keys2e}
 
-\def\g at xsb@version at tl{0.9}
-\def\g at xsb@date at tl{2018/01/16}
+\def\g at xsb@version at tl{0.10}
+\def\g at xsb@date at tl{2018/03/29}
 \ProvidesExplPackage{xsavebox}{\g at xsb@date at tl}{\g at xsb@version at tl}
 {saveboxes for repeating content without code replication}
 
@@ -65,7 +65,14 @@
   \tex_endinput:D
 }
 
-%package options
+%re-run message
+\msg_set:nnn{xsavebox}{rerun}{Rerun~to~get~internal~references~right!}
+\cs_new:Nn\xsb_rerun_msg:{
+  \cs_if_exist:NF\g_xsb_rerunwarned_tl{
+    \tl_new:N\g_xsb_rerunwarned_tl
+    \AtEndDocument{\msg_warning:nn{xsavebox}{rerun}}
+  }
+}
 
 %unknown package option error message
 \msg_set:nnnn{xsavebox}{unknown~package~option}{Unknown~package~option~`#1'.}{
@@ -73,6 +80,7 @@
   perhaps~it~is~spelled~incorrectly.
 }
 
+%package options
 \tl_gset:Nn\g_xsb_margin_tl{3pt}
 \keys_define:nn{xsavebox}{
   margin .code:n = {
@@ -87,10 +95,20 @@
 
 \ProcessKeysOptions{xsavebox}
 
+\int_new:N\g_xsb_id_int
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % content insertion (referencing, actually)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\DeclareDocumentCommand\xusebox{m}{\tl_use:c{the#1}}
+\DeclareDocumentCommand\xusebox{m}{
+  \tl_if_exist:cF{the#1}{\msg_error:nnn{xsavebox}{save-box~undefined}{#1}}
+  \tl_use:c{the#1}
+}
+\msg_set:nnnn{xsavebox}{save-box~undefined}{
+  Save-box~`#1'~undefined~\msg_line_context:.
+}{
+  Save-box~`#1'~must~be~defined~/before/~use.
+}
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % saving content
@@ -231,12 +249,32 @@
   }
   \box_set_ht:Nn#4{\height+\g_xsb_margin_tl}
   \box_set_dp:Nn#4{\depth+\g_xsb_margin_tl}
-  %distill box to Form XObject
+  \tl_if_exist:cF{xsb@\int_use:N\g_xsb_id_int}{
+    \tl_gset:cn{xsb@\int_use:N\g_xsb_id_int}{true}
+    \xsb_rerun_msg:
+  }
   \xsb_pop_props_to:N\l_tmpa_tl
-  \pbs_pdfxform:nnnnn{1}{0}{\l_tmpa_tl}{
-    \cs_if_exist_use:N\ocgbase_insert_oc:}{#4}
+  %distill box to Form XObject, if used (ref'ed)
+  \bool_if:cT{c_\tl_use:c{xsb@\int_use:N\g_xsb_id_int}_bool}{
+    \pbs_pdfxform:nnnnn{1}{0}{\l_tmpa_tl}{
+      \cs_if_exist_use:N\ocgbase_insert_oc:}{#4}
+  }
+  %for tracking box usage
+  \iow_now:Nx\@mainaux{
+    \token_to_str:N\pbs at newkey{xsb@\int_use:N\g_xsb_id_int}{false}
+  }
   %define command for inserting the m-boxed XObject reference
   \tl_gset:cx{the#1}{
+    \exp_not:N\tl_if_exist:cF{xsb_\int_use:N\g_xsb_id_int}{
+      %mark box as `used'
+      \exp_not:N\iow_now:Nx\@mainaux{
+        \token_to_str:N\pbs at newkey{xsb@\int_use:N\g_xsb_id_int}{true}
+      }
+      \exp_not:N\tl_new:c{xsb_\int_use:N\g_xsb_id_int}
+    }  
+    \exp_not:N\bool_if:cF{c_\tl_use:c{xsb@\int_use:N\g_xsb_id_int}_bool}{
+      \exp_not:N\xsb_rerun_msg:
+    }
     \exp_not:N\xsb_beginLTR:
     \exp_not:N\makebox[\l_xsb_new_wd_tl][#3]{
       \exp_not:N\hbox_to_wd:nn{\l_xsb_wd_tl}{
@@ -243,11 +281,15 @@
         \exp_not:N\vrule~width~\c_zero_dim~height~\l_xsb_ht_tl~
           depth~\l_xsb_dp_tl
         \exp_not:N\skip_horizontal:n{-\g_xsb_margin_tl}
-        \exp_not:N\pbs_pdfrefxform:n{\pbs_pdflastxform:}\hss
+        \bool_if:cT{c_\tl_use:c{xsb@\int_use:N\g_xsb_id_int}_bool}{
+          \exp_not:N\pbs_pdfrefxform:n{\pbs_pdflastxform:}
+        }
+        \hss
       }
     }
     \exp_not:N\xsb_endLTR:
   }
+  \int_gincr:N\g_xsb_id_int
 }
 
 \box_new:N\l_xsb_box     %for saving the re-aligned content



More information about the tex-live-commits mailing list