pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.15k stars 108 forks source link

Support for the Tagging Project #1370

Open u-fischer opened 3 weeks ago

u-fischer commented 3 weeks ago

Brief outline of the proposed feature

I'm currently trying to implement some first support to properly tag tikz pictures and have a few request to tikz/pgf here.

Predefine and reserve the keys alt and actualtext.

In various cases user will have to provide an alternative text or an actualtext for a picture:

\begin{tikzpicture}[alt=A duck]
\duck
\end{tikzpicture}

I will provide the needed tagging code, but it would be nice if tikz would predefine the keys for this purpose so that users can add such texts even if tagging is not active (\includegraphics knows the alt keys already too and I will add actualtext).

Interface for tagging code around nodes.

I must be able to add tagging code around nodes. Currently I'm redefining for this two internal commands of pgf:

   \def\pgfsys@begin@text
    {
      \bool_if:NT\l__tag_tikzpicture_usetext_bool
        {\ResumeTagging{\tikzpicture}} 
      \tag_socket_use:n{tikzpicture/textbegin}
    }
   \def\pgfsys@end@text
    {
      \tag_socket_use:n{tikzpicture/textend}
      \bool_if:NT\l__tag_tikzpicture_usetext_bool
        {\SuspendTagging{\tikzpicture} } 
    }

This looks more or less ok: as far as I could see the commands are only used for postscript + svg where tagging is not active. But dedicated commands at the same place would be better.

Getting the BBox

In some case I have to calculate the BBox, these are the absolute coordinates on the page of the bottom/left and top/right corners of the picture. I'm using remember picture and then the following code to calculate the coordinates. This works fine (I currently do not care about cases where parts of the picture are outside the bounding box), but here too it would be nice, if there were a public tikz command that one could use:

% redefine `\pgfqpoint` locally and then call  `pgf@sys@pdf@mark@pos@pgfid\the\pgf@picture@serial@count`:
   \cs_set:Npn\pgfqpoint##1##2
    {         
      \dim_to_decimal_in_bp:n {##1+ \pgf@picminx}
      \c_space_tl
      \dim_to_decimal_in_bp:n {##2+ \pgf@picminy}
      \c_space_tl
      \dim_to_decimal_in_bp:n {##1+ \pgf@picmaxx}
      \c_space_tl
      \dim_to_decimal_in_bp:n {##2+ \pgf@picmaxx}          
    }   
   \cs_if_exist:cT { pgf@sys@pdf@mark@pos@pgfid\the\pgf@picture@serial@count }
    {
      \__tag_prop_gput:cne
        { g__tag_struct_ \g__tag_struct_stack_current_tl _prop }
        { A } 
        {
           << 
             /O /Layout /BBox~
             [
               \use:c 
                { pgf@sys@pdf@mark@pos@pgfid\the\pgf@picture@serial@count }
             ]
           >>   
        }
     }

Usage example

No response