0

Please,help me,how i can correct do tagging of the tables. I try to do it,but i get an error:

! LaTeX Error: Illegal character in array arg.

I guessed,what this error happens because to the \tabular command i give nothing as argument. I tryed give one,two,three and four arguments,but this error is not disappear. Using \message command i noticed,what each argument,which i give to command,using \cs_gset_protected:cpn{tabular}#1 #2 #3 #4{\some_code} gives to command tabular for each argument only one character. for example for \tabular{ccc} i have things like { c c c for each argument. Help me please fix this error. Also help me please,what command should i use for table,tabbing and any other table environment,for each line and cell. I will do tagging of this environments myself,if i will know this commands. Thank you very much for your help with fixing of error and with commands for table environments.

\documentclass{article}
\usepackage{tagpdf}
\tagpdfsetup{tabsorder=structure,uncompress,activate-all,add-new-tag=Title/P,interwordspace=true}
\ExplSyntaxOn
\makeatletter
\cs_set_eq:cc{orig@tabular}{tabular}
\cs_set_eq:cc{orig@endtabular}{endtabular}
\cs_gset_protected:cpn{tabular}{
\cs_new_protected:Npn \l__tab_char: {
\tagmcend
\tagstructend
\tagstructend
\tagstructbegin{tag=TD}
\tagstructbegin{tag=P}
\tagmcbegin{tag=P}
    \c_alignment_token
}
\char_set_active_eq:NN \& \l__tab_char:
\char_set_catcode_active:N \&
\tagstructbegin{tag=Table}
\tagstructbegin{tag=TBody}
\use:c{orig@tabular}
\let\orig@startfield=\@startfield
\let\orig@stopfield=\@stopfield
\let\orig@startline=\@startline
\let\orig@stopline=\@stopline
\renewcommand{\@startfield}{
\tagstructbegin{tag=TD}
\tagstructbegin{tag=P}
\tagmcbegin{tag=P}
\orig@startfield
}
\renewcommand{\@stopfield}{
\orig@stopfield
\tagmcend
\tagstructend
\tagstructend
}
\renewcommand{\@startline}{
\tagstructbegin{tag=TR}
\tagstructbegin{tag=TD}
\tagstructbegin{tag=P}
\tagmcbegin{tag=P}
\orig@startline
}
\renewcommand{\@stopline}{
\orig@stopline
\tagmcend
\tagstructend
\tagstructend
\tagstructend
}
}
\cs_gset_protected:cpn{endtabular}{
\use:c{orig@endtabular}
\tagstructend
\tagstructend
}
\makeatother
\ExplSyntaxOff
\begin{document}
\tagstructbegin{tag=Document}
\begin{tabular}{cc}
a&b
c&d
\end{tabular}
\tagstructend
\end{document}
2
  • it isn't clear why you are using \use:c here. \use:c{orig@tabular}\let is just an inefficient equivalent to \orig@tabular\let so the argument to tabular is \let not {ccc} hence the error. You need \orig@tabular to be the very last thing in the redefinition, so it picks up the argument from the document. Commented Oct 31, 2020 at 20:10
  • also you have redefinitions of startline stopline etc inside your tabular redefinition, but they are unrelated to tabular and are internal commands for the tabbing environment. Commented Oct 31, 2020 at 20:14

1 Answer 1

1

It's not entirely clear the intention here but the error is because you were calling \orig@tabular in the middle of the definition so its argument is the following token (\let) not the {cc} from the document.

In this case all the following tokens are redefinitions of internal commands from tabbing not relevant to tabular so I simply deleted them, it runs but with some warnings about the tag structure.

\documentclass{article}
\usepackage{tagpdf}
\tagpdfsetup{tabsorder=structure,uncompress,activate-all,add-new-tag=Title/P,interwordspace=true}
\ExplSyntaxOn
\makeatletter
\cs_set_eq:NN\orig@tabular\tabular
\cs_set_eq:NN\orig@endtabular\endtabular
\cs_gset_protected:Npn\tabular{
\cs_new_protected:Npn \l__tab_char: {
\tagmcend
\tagstructend
\tagstructend
\tagstructbegin{tag=TD}
\tagstructbegin{tag=P}
\tagmcbegin{tag=P}
    \c_alignment_token
}
\char_set_active_eq:NN \& \l__tab_char:
\char_set_catcode_active:N \&
\tagstructbegin{tag=Table}
\tagstructbegin{tag=TBody}
\orig@tabular
}
\cs_gset_protected:Npn\endtabular{
\orig@endtabular
\tagstructend
\tagstructend
}
\makeatother
\ExplSyntaxOff
\begin{document}
\tagstructbegin{tag=Document}
\makeatletter
\begin{tabular}{cc}
a&b\\
c&d
\end{tabular}
\tagstructend
\end{document}

warns

tagpdf: WARN! MC1 has no kids
tagpdf: WARN! MC1 has no kids
tagpdf: WARN! MC2 has no kids
tagpdf: WARN! MC2 has no kids
11
  • I want to do tagging of all table: each line of table and each cell for the table,so i need in redefining of \@startline and \@stopline with \@startfield and \@stopfield inside a table environments,but i have some problems with arguments of this commands. In fact inside my package i did property,which contains table,tabular,tabin,etc,so i redefine commands for all of this environments. Also i have a question: Why instead of c you used N? Thank you very much for your help. Also help me please,what commands should i use for tagging of each cell and line of tabular. Commented Nov 1, 2020 at 1:56
  • @AleksandrKozlovskiy Redefining \@startline and \@stopline will have no effect as those commands are completely unrelated to the table and tabular environments. You may need to redefine them for tabbing but such a definition should not be local to a redefinition of tabular that can not work at all. Using N is vastly more efficient than c in time and space: c allows a name to be constructed but it is a constant here. \use:c{tabular} is 10 tokens and expands in two steps to \tabular. compared to \tabular which is one token and is \tabular with no expansion needed. Commented Nov 1, 2020 at 9:52
  • Ok,so for table and tabular i can use \@start/stopline commands and &? Should i redefine \start/stopfield commands locally for tabbing environment. In what cases using c mor efficient than N? Commented Nov 1, 2020 at 12:41
  • Why for use:c{tabular} i have 10 tokens,because it seems we have 9 tokens: { t a b u l a r },or \,which not use in this variant,is token to? Commented Nov 1, 2020 at 12:48
  • @AleksandrKozlovskiy you could use commands \@startline but it would be very confusing, why use names from tabbing in a redefined tabular? c is never more efficient. \csname abc\endcsname expands to \abc so will always take an extra expansion step. Commented Nov 1, 2020 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .