% !Mode:: "TeX:DE:UTF-8:Main"

\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{pdfversion=1.7,lang=de-DE}

\documentclass{article}

\usepackage{tagpdf}
\tagpdfsetup{tabsorder=structure,
             activate}
\usepackage{iftex}
\iftutex
  \usepackage{fontspec}
  \usepackage{unicode-math}
  \usepackage{luacode}
  \newfontface\zerowidthfont{freeserif}
\else
  \usepackage[T1]{fontenc}
\fi


\usepackage{graphicx}
% This is not a perfectly tagged document!
% It doesn't use paratagging!
% one sentence is not marked (luatex will mark it as artifact)
% with pdflatex there is a encoding problem with the math

\begin{document}
\tagpdfparaOff
\pagestyle{empty}


%This isn't read by voice software
Etwas unmarkierter Text.

%This read ok by voice software
\tagstructbegin{tag=P}
  \tagmcbegin{tag=P}
   Ein Satz ohne Umlaute.
  \tagmcend
\tagstructend

%This read ok by  nvda, but adobe has difficulties with the umlauts
\tagstructbegin{tag=P}
  \tagmcbegin{tag=P}
   Grüße an die Welt und die öde Wüste.
  \tagmcend
\tagstructend

\newpage
% alttext is read,
% actualtext copy & pasted
\tagstructbegin{tag=P,alttext=Dies ist ein Text,actualtext=Copy}
  \tagmcbegin{tag=P}
   Test
  \tagmcend
\tagstructend

%alttext is read,
%actualtext copy & pasted
\tagstructbegin{tag=P}
 \tagmcbegin{tag=P,alttext=Dies ist ein zweiter Text,actualtext=Copy}
  Test
 \tagmcend
\tagstructend


%nvda: alttext of structure is read
%adobe: alttext of inner mc is read
% result of copy & paste of this page in adobe reader:
% why twice??????
% Copy Copy
% Copy Copy
% Copystruct Copystruct

\tagstructbegin{tag=P,alttext=Dies ist der Structuretext,actualtext=Copystruct}
 \tagmcbegin{tag=P,alttext=Dies ist der innere  Text,actualtext=Copymc}
  Test
 \tagmcend
\tagstructend



\newpage
% test of "Formula" tag:
% content is more or less ignored. This is not against the documentation:
% Formula is explicitly describes as an "illustration", something with a content
% which can not be read directly.
% But it is a problem that nvda ignores it even with an alt text.

%test of Formula tag + alttext in the mc
%pdflatex
%nvda: content is ignored
%adobe: reads the alt text but without {} and ()

%luatex (unicode-math):
% nvda: doesn't read
%adobe: doesn't read  (warning "empty page")

\tagstructbegin{tag=Formula}
 \tagmcbegin {tag=Formula,alttext={\frac{a}{b}+c + \int_1^n f(x)}}
  xxx $\frac{a}{b}+c + \int_1^n f(x)$
 \tagmcend
\tagstructend

\newpage

%test of Formula tag + alttext in the struct
\tagstructbegin{tag=Formula,alttext=Dies ist eine Formel}
 \tagmcbegin {tag=Formula}
  formula
 \tagmcend
\tagstructend

\newpage
% test of Formula tag without alttext
% pdflatex
% adobe: reads it more or less (without commands naturally)
% nvda: ignores it

%lualatex
%nvda: ignores it
%adobe: ignores it

\tagstructbegin{tag=Formula}
 \tagmcbegin {tag=Formula}
 formula: $\frac{a}{b}+c + \int_1^n f(x)$
 \tagmcend
\tagstructend

\newpage
% luatex:
% nvda: reads the alttext ok, {} and () are only read if the symbol level is (at leat) "most"
% adobe: something is read but it is not understable

\tagstructbegin{tag=P}
 \tagmcbegin {tag=P,alttext={\frac{x}{y}+c + \int_1^n f(x)}}
  $\frac{x}{y}+c + \int_1^n f(x)$
 \tagmcend
\tagstructend

%pdftex
% sum is read as "pi"
%luatex
%adobe: almost nothing read (only 1 and =)
%nvda: similar, obviously both have problems with the unicode math symbols
\tagstructbegin{tag=P}
 \tagmcbegin {tag=P}
  $\sum_1^n (1) = n $
 \tagmcend
\tagstructend

\newpage

\tagmcbegin{tag=P,
 actualtext=Ente,
 alttext=Dies ist eine Ente}
 %% a char is needed so that actualtext works,
 \ifluatex
  {{\zerowidthfont^^^^200c}}%
 \else {\makebox[0pt][l]{.}} \fi%
 %it seems not to be needed for alttext and voice software ....
 \includegraphics[width=1cm]{example-image-duck}
\tagmcend

\tagmcbegin{tag=P,
 actualtext=Ente,
 alttext=Dies ist eine zweite Ente}
 %% a char is needed so that actualtext works,
 %\tagpdfifluatexTF
 %  {{\zerowidthfont^^^^200c}}%
 %  {\makebox[0pt][l]{.}}%
 %it seems not to be needed for alttext and voice software ....
 \includegraphics[width=1cm]{example-image-duck}
\tagmcend


\end{document}
