如何正确重新定义 itemize 环境

如何正确重新定义 itemize 环境

我尝试自动标记列表。看来,我的代码在所有环境中都运行良好,但对于 itemize,我收到 tagpdf 错误,因为我在结构堆栈中没有任何结构。另外,看来,在描述环境中显示,标签不为空,但在 pdf 中我有空的结构元素。此外,如果我在 tagpdf 包的通用模式下使用 description 而不是 itemize,我在 pdf 中得到:scriptionlabel test scriptionlabel new test 而不是:test new test 在 lua 模式下一切正常。是的,现在这个问题解决了,因为我检查了标签是否为空,但我想了解为什么会发生这种情况,因为之前在某些代码中我遇到过非常类似的问题,当参数的值在 pdf 中时,即使在 lua 模式下也是如此,所以我想了解,为什么会发生这种情况,例如为什么在这种情况下会发生这种情况。请帮我解决这个问题,谢谢大家的帮助。

\documentclass{article}
\usepackage{tagpdf}
\tagpdfsetup{tabsorder=structure,uncompress,activate-all,interwordspace=true}

\ExplSyntaxOn
%command for labels
\prop_gset_from_keyval:Nn \g__aleksandr_labels_prop{descriptionlabel=1,labelenumi=0,labelenumii=0,labelenumiii=0,labelenumiv=0,labeleitemi=1,lableitemii=1,labelitemiii=1,labelitemiv=1}
\prop_map_inline:Nn \g__aleksandr_labels_prop{
\cs_set_eq:cc{orig@#1}{#1}
%set protected command depends of number of arguments,which you can see in \g__aleksandr_labels_prop. If we have one or more arguments,we check,if it an empty and if yes,we not tagging label.
\int_case:nnF{#2}{{0}{\cs_gset_protected:cpn { #1 }
     {
\tagstructbegin{tag=LI}
\tagstructbegin{tag=Lbl}
\tagmcbegin{tag=Lbl}
\use:c { orig@#1 }
\tagmcend
\tagstructend
}}}
{\cs_gset_protected:cpn { #1 }##1
     {
\tagstructbegin{tag=LI}
%Why in enumerate not increased counter and we have number not only in label,but in item.
\tl_if_empty:NTF ##1 {\use:c { orig@#1 }##1}{\tagstructbegin{tag=Lbl}
\tagmcbegin{tag=Lbl}
\use:c { orig@#1 }##1
\tagmcend
\tagstructend
}
}
}
}

% The declaration is global. The integer is initially equal to 0 (see
% interface3.pdf).
\int_new:N \g__aleksandr_list_level_int

\cs_new_eq:NN \__aleksandr_orig_start_list:nn \list
\cs_new_eq:NN \__aleksandr_orig_end_list: \endlist
\cs_new_eq:NN \__aleksandr_orig_item: \item
% Simple macro to reduce redundancy and the length of some lines. It expands
% to the list boolean variable name for the current level **without its
% backslash**.
\cs_new:Npn \__aleksandr_list_level_bool_name:
  {
    g__aleksandr_first_item_ \int_use:N \g__aleksandr_list_level_int _bool
  }

\renewcommand \list
  {
    \int_compare:nNnF { \g__aleksandr_list_level_int } = { 0 }
      {
        % We need check, if we have items in previous level,and if yes, close mc
        % and struct before starting of the list.
        \bool_if:cT { \__aleksandr_list_level_bool_name: }
          {
            \tagmcend \tagstructend
            %We close previous LI and LBody
            \tagstructend \tagstructend
            \bool_gset_false:c { \__aleksandr_list_level_bool_name: }
          }

        \tagstructbegin { tag=LI }
        \tagstructbegin { tag=LBody }
      }

    \int_gincr:N \g__aleksandr_list_level_int
    \bool_if_exist:cF { \__aleksandr_list_level_bool_name: }
      { \bool_new:c { \__aleksandr_list_level_bool_name: } }

    \tagstructbegin { tag=L }
    \__aleksandr_orig_start_list:nn
  }

\renewcommand \endlist
  {
    \bool_if:cTF { \__aleksandr_list_level_bool_name: }
      {
        \tagmcend
        \tagstructend
        \tagstructend
        \tagstructend
        \bool_gset_false:c { \__aleksandr_list_level_bool_name: }
      }
      {
        % If we haven't items, but we have level more then one, we have sublist
        % before, so we should close LI and LBody.
        \int_compare:nNnF { \g__aleksandr_list_level_int - 1 } = { 0 }
          { \tagstructend \tagstructend }
      }
    \int_gdecr:N \g__aleksandr_list_level_int
    \__aleksandr_orig_end_list:
    \tagstructend
  }

\renewcommand \item {
    \bool_if:cTF { \__aleksandr_list_level_bool_name: }
      {
        \iow_term:n { True~value }
        % We have an item before, so we must close the last item, LBody and LI.
        \tagmcend \tagstructend \tagstructend \tagstructend
      }
      {
        \iow_term:n { False~value }
        % This code is only executed once.
        \bool_gset_true:c { \__aleksandr_list_level_bool_name: }
      }
\__aleksandr_orig_item:
    \tagstructbegin {tag=LBody}
    \tagstructbegin {tag=P}
    \tagmcbegin {tag=P}
}
%why for itemize and enumerate \endlist is not calls? We should replace \endenumerate and \enditemize commands on \endlist command,to fix it.
\let\endenumerate=\endlist
\let\enditemize=\endlist
\ExplSyntaxOff
\title{test document}
\pagestyle{empty}
\begin{document}
%now it not works,because we not redefine center environment yet
%\maketitle{}
\tagstructbegin{tag=Document}
\begin{itemize}
\item test
\item new test
\end{itemize}
\everypar{\message{new~paragraph}}
Test

New test
\tagstructend
\end{document}

相关内容