I have a test with check boxes made in LaTeX for result recognition in queXF. This works fine, but if I change something in source boxes are being relocated and queXF recognition boxes are becoming invalid.
Is it possible to make output of absolute box element position and sizes to external file?
For example, I have the following code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\checkBox}[1]{
\begin{tikzpicture}[color=black, line width=0.2mm]
\draw (0,0) rectangle (5mm,5mm);
\end{tikzpicture}
}
\begin{document}
Question:\\
\checkBox{Q1A}~Answer A\\
\checkBox{Q1B}~Answer B\\
\checkBox{Q1C}~Answer C\\
\checkBox{Q1D}~Answer D\\
\end{document}
Output is:
And I want to get information about box positions and sizes (if possible) according to their IDs. Maybe something like this:
\Q1A{3cm}{2cm}{5mm}{5mm}
\Q2B{3cm}{2.5cm}{5mm}{5mm}
Or in any other format that could be parsed.
Any ideas are greatly appreciated.
Best Answer
If you use the
remember picture
option oftikzpicture
the picture origin is written to the auxiliary file (.aux
). The used unit is scaled pointssp
which is 65536sp = 1pt = 1/72.27inch. The origin is IIRC the lower left page corner. You can also save any content in a box register and write its size into the auxiliary file or another one.Even better is the
zref-abspos
package which allows you to get the absolute position of any point, also insp
. You need to place a\zsavepos{<name>}
at these coordinates and then can get the coordinates after one compilation using\zposx{<name>}
and\zposy{<name>}
. The manual states that it is only good for relative positions because there is no official reference origin, but in all my tests it was also the lower left page corner.The following code should demonstrate this:
It writes a
.pos
file which holds the positions like this:The format can also be changed to get the values in
pt
or another unit, or the origin plus size instead of the absolute position of the lower left and upper right corner like it is now.For mm output replace the
\write
content with:and add the following macro:
Then you get:
If you mind the shown precision and like to round the numbers instead have a look at
\pgfmathprintnumber
of PGF/TikZ. However, if you parse these files anyway you can do it then as well.If you are using DVI mode (i.e.
latex
notpdflatex
), thetikzpicture
is created using PostScript code executed bydvips
after the TeX processing. In this case both nodes are not yet placed and get the same coordinates which should be the origin of the picture. Instead I would only save one point and measure the size of the picture to get the other one. Note that I added some PGF/TiKZ code to make sure that\zsavepos
doesn't influence the size of the picture.