From 08389ad18f40230695bf434e4a1a5de4f83b1862 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Fri, 24 May 2019 21:20:13 +0000
Subject: ocgx2 (24may19)

git-svn-id: svn://tug.org/texlive/trunk@51213 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty | 347 +++++++++++++++++++++++-----
 1 file changed, 292 insertions(+), 55 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty')

diff --git a/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty b/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty
index 72b51ce1940..404d849b962 100644
--- a/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty
+++ b/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty
@@ -15,7 +15,9 @@
 %
 % With ocgx2, PDF layers may extend across page breaks.
 %
-% Adds some minor improvements, such as package options, remembering option
+% ocgx2 implements OCMDs (optional content membership dictionaries)
+%
+% Adds some minor improvements, such as package options, remembering option.
 % settings of reopened ocgs, correct behaviour of ocg switching links that were
 % themselves placed on layers, compatibility with the animate and media9
 % packages.
@@ -38,8 +40,8 @@
 \RequirePackage{xparse}
 \RequirePackage{l3keys2e}
 
-\def\g@ocgxii@date@tl{2019/01/02}
-\def\g@ocgxii@version@tl{0.40}
+\def\g@ocgxii@date@tl{2019/05/24}
+\def\g@ocgxii@version@tl{0.41}
 
 \ProvidesExplPackage{ocgx2}{\g@ocgxii@date@tl}{\g@ocgxii@version@tl}
 {ports `ocgx' functionality to dvips+ps2pdf, xelatex and dvipdfmx}
@@ -60,6 +62,8 @@
   }
 }
 
+\msg_set:nnn{ocgx2}{generic~msg}{#1\\#2}
+
 \msg_set:nnn{ocgx2}{missing~package}{
   Package~`#1'~must~be~loaded~before~ocgx2.\\\\
   Put\\\\
@@ -122,8 +126,8 @@
 
   showingui .choices:nn = {true,false,always,never,iffirstuse}{
     \bool_if:nTF{
-      \str_if_eq_x_p:nn{#1}{false} ||
-      \str_if_eq_x_p:nn{#1}{never}
+      \str_if_eq_p:ee{#1}{false} ||
+      \str_if_eq_p:ee{#1}{never}
     }{
       \bool_gset_false:N\g_ocgxii_showingui_bool
     }{
@@ -159,42 +163,43 @@
 
 %re-implement ocg-p's `ocg' environment
 \DeclareDocumentEnvironment{ocg}{O{}mmm}{
-  \ocgxii_beginocg:nnnn{#1}{#2}{#3}{#4}
+  \ocgxii_begin_ocg:nnnn{#1}{#2}{#3}{#4}
 }{
-  \ocgxii_endocg:
+  \ocgxii_end_ocg:
 }
 
-\cs_new_protected_nopar:Nn\ocgxii_beginocg:nnnn{
+\cs_new_protected_nopar:Nn\ocgxii_begin_ocg:nnnn{
   \group_begin:
     \ocgxii_reset_cmd_opts:  % ... to the user-set package options
-    \tl_if_exist:cTF{ocgxii@#3}{ %re-open existing layer
-      \tl_set:Nx\l_tempa_tl{\tl_use:c{ocgxii@#3.opts},#1}
-      \tl_gset:cx{ocgxii@#3.opts}{\l_tempa_tl} %new options appended
-      \keys_set:nV{ocgx2/user}\l_tempa_tl
+    \tl_set:Nx\l_ocgxii_argiv_tl{\tl_trim_spaces:n{#4}}
+    \tl_if_exist:cTF{ocgxii_ocg_#3}{ %re-open existing layer
+      \tl_set:Nx\l_tempa_tl{\tl_use:c{ocgxii_ocg_#3.opts},#1}
+      \tl_gset:cx{ocgxii_ocg_#3.opts}{\l_tempa_tl} %new options appended
+      \keys_set:nV{ocgx2/ocgenv}\l_tempa_tl
       \bool_if:nTF{ %initial visibility
-        \str_if_eq_x_p:nn{#4}{1} ||
-        \str_if_eq_x_p:nn{#4}{on} ||
-        \str_if_eq_x_p:nn{#4}{true}
+        \str_if_eq_p:ee{l_ocgxii_argiv_tl}{1} ||
+        \str_if_eq_p:ee{l_ocgxii_argiv_tl}{on} ||
+        \str_if_eq_p:ee{l_ocgxii_argiv_tl}{true}
       }{
-        \ocgbase_del_from_off_list:n{\tl_use:c{ocgxii@#3}}
+        \ocgbase_del_from_off_list:n{\tl_use:c{ocgxii_ocg_#3}}
       }{
-        \ocgbase_add_to_off_list:n{\tl_use:c{ocgxii@#3}}
+        \ocgbase_add_to_off_list:n{\tl_use:c{ocgxii_ocg_#3}}
       }
     }{
       \tl_set:Nx\l_tempa_tl{#1}
-      \tl_gset:cx{ocgxii@#3.opts}{\l_tempa_tl}
-      \keys_set:nV{ocgx2/user}\l_tempa_tl
+      \tl_gset:cx{ocgxii_ocg_#3.opts}{\l_tempa_tl}
+      \keys_set:nV{ocgx2/ocgenv}\l_tempa_tl
       \ocgbase_new_ocg:nnn{#2}{
         \l_ocgxii_view_tl\l_ocgxii_print_tl\l_ocgxii_export_tl
-      }{#4}
-      \tl_gset:cx{ocgxii@#3}{\ocgbase_last_ocg:}
+      }{\l_ocgxii_argiv_tl}
+      \tl_gset:cx{ocgxii_ocg_#3}{\ocgbase_last_ocg:}
       \iow_now:Nx\@mainaux{
         \token_to_str:N\ocgxii@newkey{ocgx2.ocg.#3}{\ocgbase_last_ocg:}
       }
     }
     \bool_if:nT{
       !\cs_if_exist:cTF{ocgx2.ocg.#3}{
-        \str_if_eq_x_p:nn{\tl_use:c{ocgx2.ocg.#3}}{\tl_use:c{ocgxii@#3}}
+        \str_if_eq_p:ee{\tl_use:c{ocgx2.ocg.#3}}{\tl_use:c{ocgxii_ocg_#3}}
       }{
         \c_false_bool
       }
@@ -204,22 +209,22 @@
         \AtEndDocument{\msg_warning:nn{ocgx2}{rerun}}
       }
     }
-    \tl_gset:cx{ocgx2.ocg.#3}{\tl_use:c{ocgxii@#3}}
+    \tl_gset:cx{ocgx2.ocg.#3}{\tl_use:c{ocgxii_ocg_#3}}
     \seq_map_inline:Nn\l_ocgxii_rbgrps_seq{% process list of radio btn groups
-      \ocgbase_add_ocg_to_radiobtn_grp:nn{##1}{\tl_use:c{ocgxii@#3}}
+      \ocgbase_add_ocg_to_radiobtn_grp:nn{##1}{\tl_use:c{ocgxii_ocg_#3}}
     }
-    \ocgbase_open_stack_push:n{\tl_use:c{ocgxii@#3}}
+    \ocgbase_open_stack_push:n{\tl_use:c{ocgxii_ocg_#3}}
     \ocgxii_stack_shipout:NN\ocgxii@ocg@stack@on@page\g_ocgbase_open_stack_seq
     % insert OCG into Order tree
     \bool_if:NT\l_ocgxii_showingui_bool{
-      \ocgbase_tree_node_begin:n{\tl_use:c{ocgxii@#3}}
+      \ocgbase_tree_node_begin:n{\tl_use:c{ocgxii_ocg_#3}}
     }
   \group_end:
-  \ocgbase_oc_bdc:n{\tl_use:c{ocgxii@#3}}
+  \ocgbase_oc_bdc:n{\tl_use:c{ocgxii_ocg_#3}}
   \ignorespaces
 }
 
-\cs_new_protected_nopar:Nn\ocgxii_endocg:{
+\cs_new_protected_nopar:Nn\ocgxii_end_ocg:{
   \unskip
   \ocgbase_oc_emc:
   \ocgbase_tree_node_end:
@@ -227,6 +232,235 @@
   \ocgxii_stack_shipout:NN\ocgxii@ocg@stack@on@page\g_ocgbase_open_stack_seq
 }
 
+% OCMD implementation
+\DeclareDocumentEnvironment{ocmd}{O{}m}{
+  \ocgxii_begin_ocmd:nn{#1}{#2}
+}{
+  \ocgxii_end_ocmd:
+}
+
+\cs_new_protected_nopar:Nn\ocgxii_begin_ocmd:nn{ % #1: id,
+  \group_begin:                                  % #2: visib. expression or policy
+    \bool_if:nF{ %do nothing if we re-open existing ocmd
+      \tl_if_blank:oTF{#1}{
+        \c_false_bool
+      }{
+        \tl_if_exist_p:c{ocgxii_ocmd_#1}
+      }
+    }{ %new ocmd
+      \ocgxii_read_ocmd_visbility:nN{#2}\l_ocgxii_ocmd_visibility_tl
+      \pbs_pdfobj:nnn{}{dict}{
+        /Type/OCMD\l_ocgxii_ocmd_visibility_tl
+      }
+      \tl_gset:cx{ocgxii_ocmd_#1}{\pbs_pdflastobj:}
+    }
+    \ocgbase_open_stack_push:n{\tl_use:c{ocgxii_ocmd_#1}}
+    \ocgxii_stack_shipout:NN\ocgxii@ocg@stack@on@page\g_ocgbase_open_stack_seq
+  \group_end:
+  \ocgbase_oc_bdc:n{\tl_use:c{ocgxii_ocmd_#1}}
+  \ignorespaces
+}
+\cs_new_protected_nopar:Nn\ocgxii_end_ocmd:{
+  \unskip
+  \ocgbase_oc_emc:
+  \ocgbase_open_stack_pop:N\l_trash_tl
+  \ocgxii_stack_shipout:NN\ocgxii@ocg@stack@on@page\g_ocgbase_open_stack_seq
+}
+
+%visibility expressions
+\cs_new_protected_nopar:Nn\ocgxii_read_ocmd_visbility:nN{
+  \int_zero:N\l_ocgxii_ve_cnt_int
+  \int_zero:N\l_ocgxii_vp_cnt_int
+  \tl_clear_new:N#2
+  \clist_map_inline:nn{#1}{\ocgxii_omcd_visib_map_func:nN{##1}#2}
+}
+\cs_new_protected_nopar:Nn\ocgxii_omcd_visib_map_func:nN{
+  \cs_set_eq:NN\Not\ocgxii_ve_check:n
+  \cs_set_eq:NN\And\ocgxii_ve_check:n
+  \cs_set_eq:NN\Or \ocgxii_ve_check:n
+  \cs_set_eq:NN\AllOn \ocgxii_vp_check:n
+  \cs_set_eq:NN\AnyOn \ocgxii_vp_check:n
+  \cs_set_eq:NN\AnyOff\ocgxii_vp_check:n
+  \cs_set_eq:NN\AllOff\ocgxii_vp_check:n
+  \tl_if_exist:cTF{ocgx2.ocg.#1}{
+    \msg_error:nnxx{ocgx2}{generic~msg}{
+      OCG~ids~cannot~be~directly~used~in~the~visibility~argument~of~an~
+      `ocmd'~environment.
+    }{\g_ocgxii_help_msg_tl}
+  }{
+    \tl_if_exist:cTF{ocgxii_#1}{
+      \str_case_e:nn{\tl_use:c{ocgxii_#1}}{
+        {VisExpr}{
+          \int_incr:N\l_ocgxii_ve_cnt_int
+          \int_compare:nNnTF{\l_ocgxii_ve_cnt_int}>{1}{
+            \msg_error:nnnn{ocgx2}{generic~msg}{
+              More~than~one~visibility~expression~passed~to~the~`ocmd'~
+              environment.
+            }{
+              At~most~one~visibility~expression~is~allowed.~A~visibility~
+              expression~is~a~boolean~expression~built~by~nesting~any~number~of~
+              \And{...},~\Or{...},~\Not{...}~commands.
+            }
+          }{
+            \ocgxii_ve_start:nN{#1}#2
+          }
+        }
+        {VisPol}{
+          \int_incr:N\l_ocgxii_vp_cnt_int
+          \int_compare:nNnTF{\l_ocgxii_vp_cnt_int}>{1}{
+            \msg_error:nnnn{ocgx2}{generic~msg}{
+              More~than~one~visibility~policy~passed~to~the~`ocmd'~environment.
+            }{
+              At~most~one~visibility~policy~out~of~\AllOn{...},~\AnyOn{...},~
+              \AnyOff{...},~\AllOff{...}~is~allowed.~Any~number~of~OCG~IDs,~
+              separated~by~commas,~may~be~passed~as~arguments~to~these~
+              commands,~but~commands~may~not~be~nested.~For~complex~visibilty~
+              relations,~consider~using~a~visibility~expression.
+            }
+          }{
+            \ocgxii_vp_start:nN{#1}#2
+          }
+        }
+      }
+    }{
+      \msg_error:nnxx{ocgx2}{generic~msg}{
+        The~visibility~argument~of~the~`ocmd'~environment~cannot~be~parsed.
+      }{\g_ocgxii_help_msg_tl}
+    }
+  }
+}
+\tl_set:Nn\g_ocgxii_help_msg_tl{
+  At~most~one~visibility~policy~and,~separated~by~a~comma,~at~most~one~
+  visibility~expression~may~be~passed~to~the~visibility~argument.~A~visibility~
+  policy~is~defined~by~one~of~\AllOn{...},~\AnyOn{...},~\AnyOff{...},~
+  \AllOff{...}.~A~visibility~expression~is~a~boolean~expression~built~by~
+  nesting~any~number~of~\And{...},~\Or{...},~\Not{...}~commands.~If~both~are~
+  provided,~the~visibility~expression~takes~precedence~over~the~policy,~but~the~
+  latter~may~be~used~as~fallback~by~non-conforming~PDF~viewers.
+}
+\int_new:N\l_ocgxii_vp_cnt_int %number of visib. policies
+\int_new:N\l_ocgxii_ve_cnt_int %number of visib. expressions
+\cs_new_protected_nopar:Nn\ocgxii_vp_start:nN{
+  \cs_set_eq:NN\AllOn \ocgxii_vp_allon:nN
+  \cs_set_eq:NN\AnyOn \ocgxii_vp_anyon:nN
+  \cs_set_eq:NN\AnyOff\ocgxii_vp_anyoff:nN
+  \cs_set_eq:NN\AllOff\ocgxii_vp_alloff:nN
+  #1#2
+}
+\cs_new_protected_nopar:Nn\ocgxii_vp_allon:nN{
+  \tl_put_right:Nx#2{/P/AllOn/OCGs~\g_ocgxii_left_bracket_tl}
+  \clist_map_inline:nn{#1}{\ocgxii_vp_map_func:nN{##1}#2}
+  \tl_put_right:Nx#2{\g_ocgxii_right_bracket_tl}
+}
+\cs_new_protected_nopar:Nn\ocgxii_vp_anyon:nN{
+  \tl_gput_right:Nx#2{/P/AnyOn/OCGs~\g_ocgxii_left_bracket_tl}
+  \clist_map_inline:nn{#1}{\ocgxii_vp_map_func:nN{##1}#2}
+  \tl_gput_right:Nx#2{\g_ocgxii_right_bracket_tl}
+}
+\cs_new_protected_nopar:Nn\ocgxii_vp_anyoff:nN{
+  \tl_gput_right:Nx#2{/P/AnyOff/OCGs~\g_ocgxii_left_bracket_tl}
+  \clist_map_inline:nn{#1}{\ocgxii_vp_map_func:nN{##1}#2}
+  \tl_gput_right:Nx#2{\g_ocgxii_right_bracket_tl}
+}
+\cs_new_protected_nopar:Nn\ocgxii_vp_alloff:nN{
+  \tl_gput_right:Nx#2{/P/AllOff/OCGs~\g_ocgxii_left_bracket_tl}
+  \clist_map_inline:nn{#1}{\ocgxii_vp_map_func:nN{##1}#2}
+  \tl_gput_right:Nx#2{\g_ocgxii_right_bracket_tl}
+}
+\cs_new_protected_nopar:Nn\ocgxii_vp_map_func:nN{
+  \cs_set_eq:NN\AllOn \ocgxii_vp_check:n
+  \cs_set_eq:NN\AnyOn \ocgxii_vp_check:n
+  \cs_set_eq:NN\AnyOff\ocgxii_vp_check:n
+  \cs_set_eq:NN\AllOff\ocgxii_vp_check:n
+  \tl_if_exist:cTF{ocgx2.ocg.#1}{
+    \tl_put_right:Nx#2{~\tl_use:c{ocgx2.ocg.#1}}
+  }{
+    \tl_if_exist:cTF{ocgxii_#1}{
+      \str_if_eq:eeTF{\tl_use:c{ocgxii_#1}}{VisPol}{
+        \msg_error:nnxx{ocgx2}{generic~msg}{
+          Visibility~policy~commands~cannot~be~nested.~For~more~complex~
+          visibilty~relations,~consider~using~a~visibility~expression.
+        }{\g_ocgxii_help_msg_tl}
+      }{
+        \msg_error:nnxx{ocgx2}{generic~msg}{
+          Visibility~policy~and~expression~commands~cannot~be~mixed.
+        }{\g_ocgxii_help_msg_tl}
+      }
+    }{
+      \msg_warning:nnx{ocgx2}{undefined~OCG}{#1}
+      \tl_if_exist:NF\g_ocgxii_refundefwarned_tl{
+        \tl_new:N\g_ocgxii_refundefwarned_tl
+        \AtEndDocument{\msg_warning:nn{ocgx2}{undefined~OCGs}}
+      }
+    }
+  }
+}
+\cs_new_protected_nopar:Nn\ocgxii_ve_start:nN{
+  \tl_put_right:Nx#2{/VE~}
+  \cs_set_eq:NN\Not\ocgxii_ve_not:nN
+  \cs_set_eq:NN\And\ocgxii_ve_and:nN
+  \cs_set_eq:NN\Or \ocgxii_ve_or:nN
+  #1#2
+}
+\cs_new_protected_nopar:Nn\ocgxii_ve_and:nN{
+  \tl_put_right:Nx#2{\g_ocgxii_left_bracket_tl/And}
+  \clist_map_inline:nn{#1}{\ocgxii_ve_map_func:nN{##1}#2}
+  \tl_put_right:Nx#2{\g_ocgxii_right_bracket_tl}
+}
+\cs_new_protected_nopar:Nn\ocgxii_ve_or:nN{
+  \tl_put_right:Nx#2{\g_ocgxii_left_bracket_tl/Or}
+  \clist_map_inline:nn{#1}{\ocgxii_ve_map_func:nN{##1}#2}
+  \tl_put_right:Nx#2{\g_ocgxii_right_bracket_tl}
+}
+\cs_new_protected_nopar:Nn\ocgxii_ve_not:nN{
+  % only one item allowed in \Not{...} argument
+  \int_compare:nNnT{\clist_count:n{#1}}>{\c_one_int}{
+    \msg_error:nnnn{ocgx2}{generic~msg}{
+      More~than~one~item~passed~to~\Not{...}.
+    }{
+      Only~one~item~is~allowed.
+    }
+  }
+  \int_compare:nNnT{\clist_count:n{#1}}={\c_one_int}{
+    \tl_put_right:Nx#2{\g_ocgxii_left_bracket_tl/Not}
+    \clist_map_inline:nn{#1}{\ocgxii_ve_map_func:nN{##1}#2}
+    \tl_put_right:Nx#2{\g_ocgxii_right_bracket_tl}
+  }
+}
+\cs_new_protected_nopar:Nn\ocgxii_ve_map_func:nN{
+  \cs_set_eq:NN\Not\ocgxii_ve_check:n
+  \cs_set_eq:NN\And\ocgxii_ve_check:n
+  \cs_set_eq:NN\Or \ocgxii_ve_check:n
+  \tl_if_exist:cTF{ocgx2.ocg.#1}{%ocg reference
+    \tl_put_right:Nx#2{~\tl_use:c{ocgx2.ocg.#1}}
+  }{
+    \tl_if_exist:cTF{ocgxii_#1}{
+      \str_if_eq:eeTF{\tl_use:c{ocgxii_#1}}{VisExpr}{
+        \cs_set_eq:NN\Not\ocgxii_ve_not:nN
+        \cs_set_eq:NN\And\ocgxii_ve_and:nN
+        \cs_set_eq:NN\Or \ocgxii_ve_or:nN
+        #1#2
+      }{
+        \msg_error:nnxx{ocgx2}{generic~msg}{
+          Visibility~policy~and~expression~commands~cannot~be~mixed.
+        }{\g_ocgxii_help_msg_tl}
+      }
+    }{
+      \msg_warning:nnx{ocgx2}{undefined~OCG}{#1}
+      \tl_if_exist:NF\g_ocgxii_refundefwarned_tl{
+        \tl_new:N\g_ocgxii_refundefwarned_tl
+        \AtEndDocument{\msg_warning:nn{ocgx2}{undefined~OCGs}}
+      }
+    }
+  }
+}
+\cs_new_protected_nopar:Nn\ocgxii_ve_check:n{VisExpr}
+\tl_set:cn{ocgxii_VisExpr}{VisExpr}
+\cs_new_protected_nopar:Nn\ocgxii_vp_check:n{VisPol}
+\tl_set:cn{ocgxii_VisPol}{VisPol}
+\tl_set:Nx\g_ocgxii_left_bracket_tl{\tl_to_str:N[}
+\tl_set:Nx\g_ocgxii_right_bracket_tl{\tl_to_str:N]}
+
 \cs_new_protected_nopar:Nn\ocgxii_stack_shipout:NN{
   \iow_shipout_x:Nx\@mainaux{
     \token_to_str:N#1{
@@ -268,7 +502,7 @@
     }
     \bool_if:nT{
       !\cs_if_exist:cTF{ocgx2.oldlnkcol.\int_use:N\g_ocgxii_page_int}{
-        \str_if_eq_x_p:nn{
+        \str_if_eq_p:ee{
           \tl_use:c{ocgx2.oldlnkcol.\int_use:N\g_ocgxii_page_int}
         }{
           \seq_use:cn{g_pending_lnkcols_on_\int_use:c{g_ocgxii_page_int}_seq}{,}
@@ -296,7 +530,7 @@
   }
   \bool_if:nT{
     !\cs_if_exist:cTF{ocgx2.oldstack.\int_use:N\g_ocgxii_page_int}{
-      \str_if_eq_x_p:nn{
+      \str_if_eq_p:ee{
         \tl_use:c{ocgx2.oldstack.\int_use:N\g_ocgxii_page_int}
       }{
         \seq_use:cn{g_pending_ocgs_on_\int_use:c{g_ocgxii_page_int}_seq}{,}
@@ -338,7 +572,7 @@
     \seq_gset_eq:cc{
       g_pending_ocgs_on_\int_use:c{g_ocgxii_page_int}_seq
     }{
-      g_pending_ocgs_on_\int_eval:n{\g_ocgxii_page_int-\c_one}_seq
+      g_pending_ocgs_on_\int_eval:n{\g_ocgxii_page_int-\c_one_int}_seq
     }
   }
   %the same for link colour stack
@@ -346,7 +580,7 @@
     \seq_gset_eq:cc{
       g_pending_lnkcols_on_\int_use:c{g_ocgxii_page_int}_seq
     }{
-      g_pending_lnkcols_on_\int_eval:n{\g_ocgxii_page_int-\c_one}_seq
+      g_pending_lnkcols_on_\int_eval:n{\g_ocgxii_page_int-\c_one_int}_seq
     }
   }
 }
@@ -378,7 +612,7 @@
 \cs_new_protected_nopar:Nn\ocgxii_ocglist_process_idlist:nn{
   \ocgxii_ocglist_reset:
   \tl_set:Nx\l_ocgxii_opt_tl{#1}\tl_remove_all:Nn\l_ocgxii_opt_tl{~}
-  \str_case_x:nnF{\l_ocgxii_opt_tl}{
+  \str_case_e:nnF{\l_ocgxii_opt_tl}{
     {onmouseup}{
       \ocgxii_ocglist_build:Nn\l_ocgxii_u_list_tl{#2}
     }
@@ -467,7 +701,7 @@
   \tl_set_eq:NN\l_ocgxii_tohide_d_tl\l_ocgxii_d_list_tl
   \tl_set_eq:NN\l_ocgxii_tohide_u_tl\l_ocgxii_u_list_tl
   %any triggers apart from mouse-up?
-  \str_if_eq_x:nnF{
+  \str_if_eq:eeF{
     \l_ocgxii_toswitch_e_tl\l_ocgxii_toswitch_x_tl\l_ocgxii_toswitch_d_tl
     \l_ocgxii_toshow_e_tl\l_ocgxii_toshow_x_tl\l_ocgxii_toshow_d_tl
     \l_ocgxii_tohide_e_tl\l_ocgxii_tohide_x_tl\l_ocgxii_tohide_d_tl
@@ -488,7 +722,7 @@
         /Subtype/Widget/Ff~65536/FT/Btn/BS<</W~0>>
         /T~(ocgx2@\int_use:N\g_ocgxii_widcount_int)
         %treat mouse-up as mouse-click --> handle through /A dictionary
-        \str_if_eq_x:nnF{}{
+        \str_if_eq:eeF{}{
           \l_ocgxii_toswitch_u_tl\l_ocgxii_toshow_u_tl\l_ocgxii_tohide_u_tl
         }{
           /A <</S/SetOCGState/State [
@@ -504,7 +738,7 @@
           ]>>
         }
         /AA <<
-          %\str_if_eq_x:nnF{}{
+          %\str_if_eq:eeF{}{
           %  \l_ocgxii_toswitch_u_tl\l_ocgxii_toshow_u_tl\l_ocgxii_tohide_u_tl
           %}{
           %  /U <</S/SetOCGState/State [
@@ -519,7 +753,7 @@
           %    }
           %  ]>>
           %}
-          \str_if_eq_x:nnF{}{ % mouse-down
+          \str_if_eq:eeF{}{ % mouse-down
             \l_ocgxii_toswitch_d_tl\l_ocgxii_toshow_d_tl\l_ocgxii_tohide_d_tl
           }{
             /D <</S/SetOCGState/State [
@@ -534,7 +768,7 @@
               }
             ]>>
           }
-          \str_if_eq_x:nnF{}{ % mouse-enter
+          \str_if_eq:eeF{}{ % mouse-enter
             \l_ocgxii_toswitch_e_tl\l_ocgxii_toshow_e_tl\l_ocgxii_tohide_e_tl
           }{
             /E <</S/SetOCGState/State [
@@ -549,7 +783,7 @@
               }
             ]>>
           }
-          \str_if_eq_x:nnF{}{ % mouse-exit
+          \str_if_eq:eeF{}{ % mouse-exit
             \l_ocgxii_toswitch_x_tl\l_ocgxii_toshow_x_tl\l_ocgxii_tohide_x_tl
           }{
             /X <</S/SetOCGState/State [
@@ -620,7 +854,7 @@
   triggerocg .choices:nn = {
     onmouseenter, onmouseexit, onmousedown, onmouseup, allactions
   }{
-    \str_if_eq_x:nnTF{\l_keys_choice_tl}{allactions}{
+    \str_if_eq:eeTF{\l_keys_choice_tl}{allactions}{
       \tl_set:Nn\l_ocgxii_trigger_tl{onmouseall}
     }{
       \tl_set_eq:NN\l_ocgxii_trigger_tl\l_keys_choice_tl
@@ -650,7 +884,7 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 \cs_new_protected:Nn\ocgxii_process_ocgref:NN{
-  \str_if_eq_x:nnF{#2}{}{
+  \str_if_eq:eeF{#2}{}{
     \tl_if_exist:cTF{ocgx2.ocg.#2}{
       \tl_put_right:Nx#1{~\tl_use:c{ocgx2.ocg.#2}}
     }{
@@ -663,8 +897,8 @@
   }
 }
 
-%command opts
-\keys_define:nn{ocgx2/user}{
+%ocg environment opts
+\keys_define:nn{ocgx2/ocgenv}{
   viewocg .choice:,
   viewocg / always .code:n={
     \tl_set:Nn\l_ocgxii_view_tl{/View<</ViewState/ON>>}},
@@ -693,8 +927,8 @@
 
   showingui .choices:nn = {true,false,always,never,iffirstuse}{
     \bool_if:nTF{
-      \str_if_eq_x_p:nn{#1}{false} ||
-      \str_if_eq_x_p:nn{#1}{never}
+      \str_if_eq_p:ee{#1}{false} ||
+      \str_if_eq_p:ee{#1}{never}
     }{
       \bool_set_false:N\l_ocgxii_showingui_bool
     }{
@@ -759,10 +993,10 @@
 \cs_new_protected_nopar:Nn\ocgxii_colourlink_nobreak_end:{
   \color@endgroup\hbox_set_end:
   \mbox{
-    \ocgbase_oc_bdc:n{\ocgxii@OCPrint}
+    \ocgbase_oc_bdc:n{\tl_use:c{ocgxii_ocg_OCPrint}}
     \hbox_to_zero:n{\box_use:N\l_tmpa_box\hss}
     \ocgbase_oc_emc:
-    \ocgbase_oc_bdc:n{\ocgxii@OCView}
+    \ocgbase_oc_bdc:n{\tl_use:c{ocgxii_ocg_OCView}}
     \group_begin:
       \exp_after:wN\HyColor@UseColor\l_ocgxii_lnkcol_tl
       \box_use_drop:N\l_tmpa_box
@@ -845,10 +1079,10 @@
       %a tiny space char should keep empty link annots from flooding the page
       % with link colour
       \hbox_overlap_left:n{\ocgxii_tiny_space_char:}
-      \ocgbase_oc_bdc:n{\ocgxii@OCPrint}
+      \ocgbase_oc_bdc:n{\tl_use:c{ocgxii_ocg_OCPrint}}
         \pbs_literal:nn{page}{-88888~-88888~99999~99999~re~f}
       \ocgbase_oc_emc:
-      \ocgbase_oc_bdc:n{\ocgxii@OCView}
+      \ocgbase_oc_bdc:n{\tl_use:c{ocgxii_ocg_OCView}}
         \group_begin:
           \exp_after:wN\HyColor@UseColor\g_ocgxii_lnkcol_tl
           \pbs_literal:nn{page}{-88888~-88888~99999~99999~re~f}
@@ -911,22 +1145,25 @@
         /Print<</PrintState/OFF>>
         /Export<</ExportState/OFF>>
       }{on}
-      \tl_gset:Nx\ocgxii@OCView{\ocgbase_last_ocg:}
-      \tl_gset:cx{ocgxii@OCView.opts}{
+      \tl_gset:cx{ocgxii_ocg_OCView}{\ocgbase_last_ocg:}
+      %in case somebody wants to reopen with \begin{ocg}...
+      \tl_gset:cx{ocgxii_ocg_OCView.opts}{
         showingui=never,printocg=never,exportocg=never}
       \ocgbase_new_ocg:nnn{OCPrint}{
         /Print<</PrintState/ON>>
         /Export<</ExportState/ON>>
       }{off}
-      \tl_gset:Nx\ocgxii@OCPrint{\ocgbase_last_ocg:}
-      \tl_gset:cx{ocgxii@OCPrint.opts}{
+      \tl_gset:cx{ocgxii_ocg_OCPrint}{\ocgbase_last_ocg:}
+      \tl_gset:cx{ocgxii_ocg_OCPrint.opts}{
         showingui=never,printocg=always,exportocg=always}
       \ocgxii_enable_ocglinks:
       \iow_now:Nx\@mainaux{
-        \token_to_str:N\ocgxii@newkey{ocgx2.ocg.OCView}{\ocgxii@OCView}
+        \token_to_str:N\ocgxii@newkey{ocgx2.ocg.OCView}{
+          \tl_use:c{ocgxii_ocg_OCView}}
       }
       \iow_now:Nx\@mainaux{
-        \token_to_str:N\ocgxii@newkey{ocgx2.ocg.OCPrint}{\ocgxii@OCPrint}
+        \token_to_str:N\ocgxii@newkey{ocgx2.ocg.OCPrint}{
+          \tl_use:c{ocgxii_ocg_OCPrint}}
       }
     }
   }{
-- 
cgit v1.2.3

