[latex3-commits] [l3svn] 02/02: l3doc: simplify the definition of \cmd, \cs, \tn and \meta.

noreply at latex-project.org noreply at latex-project.org
Fri Aug 19 09:55:05 CEST 2016


This is an automated email from the git hooks/post-receive script.

joseph pushed a commit to branch master
in repository l3svn.

commit 930b273fdf03dc0b8bcf5b78f5c9a0e70e3b1617
Author: Qing Lee <sobenlee at gmail.com>
Date:   Fri Aug 19 05:10:20 2016 +0800

    l3doc: simplify the definition of \cmd, \cs, \tn and \meta.
    
    \pdfstringdefDisableCommands is employed to deal with the expandable issue in bookmarks.
    It seems more natural.
---
 l3kernel/l3doc.dtx |  104 ++++++++++++++++++----------------------------------
 1 file changed, 35 insertions(+), 69 deletions(-)

diff --git a/l3kernel/l3doc.dtx b/l3kernel/l3doc.dtx
index 1686aed..241609b 100644
--- a/l3kernel/l3doc.dtx
+++ b/l3kernel/l3doc.dtx
@@ -1178,38 +1178,6 @@ Do not distribute a modified version of this file.
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[int]{\CodedocUseCs}
-%   To implement commands which can be used in bookmarks and moving
-%   arguments, it appears necessary to have an analogue of \cs{use:c}
-%   using only user-level category codes, or to make all auxiliaries
-%   user-level.
-%    \begin{macrocode}
-\cs_new_protected:Npn \CodedocUseCs #1 { \use:c { \tl_to_str:n {#1} } }
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}[int]{\CodedocUnexpandedTokens}
-% \begin{macro}[aux,verb]{\CodedocUnexpandedTokens }
-% \begin{macro}[aux]{\@@_exp_not:n}
-%   Function used as \cs{CodedocUnexpandedTokens} \meta{junk}
-%   \Arg{argument}.  The braces are necessary, and \meta{junk}, ignored,
-%   must not contain braces.  When used in a typesetting context, the
-%   function calls an auxiliary (whose name has a trailing space) which
-%   leaves the \meta{argument} in the input stream.  When used in an
-%   \texttt{x}-expansion context instead, the auxiliary does not expand,
-%   and \cs{@@_exp_not:n} \Arg{argument} expands to itself.  If this is
-%   written into a file and read back, the result has the original form
-%   \cs{CodedocUnexpandedTokens} \meta{junk} \Arg{argument}.
-%    \begin{macrocode}
-\cs_new:Npn \CodedocUnexpandedTokens #1 #
-  { \use:c { CodedocUnexpandedTokens ~ } \@@_exp_not:n }
-\cs_new_protected:cpn { CodedocUnexpandedTokens ~ } #1#2 {#2}
-\cs_new:Npn \@@_exp_not:n #1 { \exp_not:n { \@@_exp_not:n {#1} } }
-%    \end{macrocode}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-%
 % \begin{macro}[int, pTF]{\@@_date_compare:nNn}
 % \begin{macro}[aux]{\@@_date_compare_aux:nnnNnnn, \@@_date_compare_aux:w}
 %    \begin{macrocode}
@@ -1556,17 +1524,16 @@ Do not distribute a modified version of this file.
 % \end{macro}
 %
 % \begin{macro}{\cmd, \cs, \tn}
-%   To work within bookmarks, these commands must be expandable.  They
-%   rely on a common auxiliary \cs{@@_cmd:nn} which receives as
+%   They rely on a common auxiliary \cs{@@_cmd:nn} which receives as
 %   arguments the options and some tokens whose string representation
 %   starts with a backslash (to support cases such as |\cs{pkg_\ldots}|,
 %   we do not turn the whole argument into a string).
 %    \begin{macrocode}
-\DeclareExpandableDocumentCommand \cmd { O{} m }
+\DeclareDocumentCommand \cmd { O{} m }
   { \@@_cmd:no {#1} { \token_to_str:N #2 } }
-\DeclareExpandableDocumentCommand \cs  { O{} m }
+\DeclareDocumentCommand \cs  { O{} m }
   { \@@_cmd:no {#1} { \c_@@_backslash_tl #2 } }
-\DeclareExpandableDocumentCommand \tn  { O{} m }
+\DeclareDocumentCommand \tn  { O{} m }
   {
     \@@_cmd:no
       { module = TeX , replace = false , #1 }
@@ -1576,12 +1543,36 @@ Do not distribute a modified version of this file.
 % \end{macro}
 %
 % \begin{macro}{\meta}
-%   To work within a bookmark, this command must be expandable.
+%   A document-level command.
 %    \begin{macrocode}
-\DeclareExpandableDocumentCommand { \meta } { m }
+\DeclareDocumentCommand \meta { m }
   { \@@_meta:n {#1} }
 %    \end{macrocode}
 % \end{macro}
+
+% \begin{macro}[aux]
+%   {
+%     \@@_pdfstring_cmd:w,
+%     \@@_pdfstring_cs:w,
+%     \@@_pdfstring_meta:w
+%   }
+%   To work within a bookmark, these commands must be expandable.
+%    \begin{macrocode}
+\DeclareExpandableDocumentCommand
+  { \@@_pdfstring_cmd:w } { o m } { \token_to_str:N #2 }
+\DeclareExpandableDocumentCommand
+  { \@@_pdfstring_cs:w }  { o m } { \textbackslash \tl_to_str:n {#2} }
+\cs_new:Npn \@@_pdfstring_meta:w #1
+  { < \tl_to_str:n {#1} > }
+\pdfstringdefDisableCommands
+  {
+    \cs_set_eq:NN \cmd  \@@_pdfstring_cmd:w
+    \cs_set_eq:NN \cs   \@@_pdfstring_cs:w
+    \cs_set_eq:NN \tn   \@@_pdfstring_cs:w
+    \cs_set_eq:NN \meta \@@_pdfstring_meta:w
+  }
+%    \end{macrocode}
+% \end{macro}
 %
 % \begin{macro}{\Arg, \marg, \oarg, \parg}
 %   |\marg{text}| prints \marg{text}, \enquote{mandatory argument}.\\
@@ -1744,12 +1735,7 @@ Do not distribute a modified version of this file.
 %    \end{macrocode}
 %
 % \begin{macro}[int]{\@@_cmd:nn, \@@_cmd:no}
-% \begin{macro}[aux]{\@@_cmd_aux:nn}
-%   Within a |pdfstring|, use the second argument directly.  Otherwise
-%   call \cs{@@_cmd_aux:nn}: the indirection through
-%   \cs{CodedocUnexpandedTokens} and \cs{CodedocUseCs} makes things
-%   work when they pass through a
-%   file.  Apply the key--value \meta{options}~|#1| after setting some
+%   Apply the key--value \meta{options}~|#1| after setting some
 %   default values.  Then (unless |replace=false|) replace |@@| in~|#2|,
 %   which is a bit tricky: the |_| must be given the catcode expected by
 %   \cs{@@_replace_at_at:N}, but should be reverted to their original
@@ -1760,24 +1746,14 @@ Do not distribute a modified version of this file.
 %   must be turned into \tn{@xobeysp}.  Finally, produce an index entry.
 %   Indexing is suppressed when \cs{l_@@_cmd_noindex_bool} is true.
 %    \begin{macrocode}
-\cs_new:Npn \@@_cmd:nn #1#2
-  {
-    \texorpdfstring
-      {
-        \CodedocUnexpandedTokens
-          { \CodedocUseCs { @@_cmd_aux:nn } {#1} {#2} }
-      }
-      {#2}
-  }
-\cs_generate_variant:Nn \@@_cmd:nn { no }
-\cs_new_protected:Npn \@@_cmd_aux:nn #1#2
+\cs_new_protected:Npn \@@_cmd:nn #1#2
   {
     \bool_set_false:N \l_@@_cmd_noindex_bool
     \bool_set_true:N \l_@@_cmd_replace_bool
     \tl_set:Nn \l_@@_cmd_index_tl { \q_no_value }
     \tl_set:Nn \l_@@_cmd_module_tl { \q_no_value }
     \keys_set:nn { l3doc/cmd } {#1}
-    \tl_set:No \l_@@_cmd_tl { \token_to_str:N #2 }
+    \tl_set:Nn \l_@@_cmd_tl {#2}
     \bool_if:NT \l_@@_cmd_replace_bool
       {
         \tl_set_rescan:Nnn \l_@@_tmpb_tl { } { _ }
@@ -1815,14 +1791,13 @@ Do not distribute a modified version of this file.
           \l_@@_index_internal_bool
       }
   }
+\cs_generate_variant:Nn \@@_cmd:nn { no }
 %    \end{macrocode}
 % \end{macro}
-% \end{macro}
 %
 % \begin{macro}
 %   {
 %     \@@_meta:n,
-%     \@@_meta_aux:n,
 %     \@@_ensuremath_sb:n,
 %     \@@_meta_original:n
 %   }
@@ -1833,16 +1808,7 @@ Do not distribute a modified version of this file.
 %   \cs{@@_ensuremath_sb:n} (which creates math subscripts), then runs
 %   the code used for \tn{meta} in \pkg{doc.sty}.
 %    \begin{macrocode}
-\cs_new:Npn \@@_meta:n #1
-  {
-    \texorpdfstring
-      {
-        \CodedocUnexpandedTokens
-          { \CodedocUseCs { @@_meta_aux:n } {#1} }
-      }
-      { < #1 > }
-  }
-\cs_new_protected:Npn \@@_meta_aux:n #1
+\cs_new_protected:Npn \@@_meta:n #1
   {
     \tl_set:Nn \l_@@_tmpa_tl {#1}
     \tl_map_inline:nn

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the latex3-commits mailing list