On 03/08/2015 11:47, Benjamin Berg wrote:
> Hi,
>
> I am having trouble to understand what the difference between
> \addtocounter and \int_gincr:N is. When used inside a tabularx
> environment, the \int_* functions do not work correctly, but the normal
> LaTeX counters do.
>
> Maybe the idea of even using counters in a tabularx environment like
> this is totally wrong[1], but it feels to me like the two commands
> should behave in the same way. So either I am not grasping some
> concepts (feel free to just point me to an explanation) or there might
> even be a small bug.
>
> So, the attached document will print two tables. For each cell the
> output of "\int_use:N \g_test_int,~\thetestcount" is displayed. The
> counter is behaving as I expect while the \g_test_int has different
> values inside tabularx.
>
>
> tabularx:
> 3, 1    4, 2    1, 3    2, 4
> 3, 1    4, 2
>
> and tabular:
> 1, 1    2, 2    3, 3    4, 4
> 1, 1    2, 2
>
> It looks like this has to do with the fact that in the second row there
> are empty cells. But it still baffles me, that the latex counters
> behave correctly, while latex 3 integers do not.
>
> Regards,
> Benjamin
>
> [1] It is very likely that I will drop the tabularx anyways.
>

tabularx typesets its body multiple times with trial settings to find
the right widths. So in general any command that is doing anything with
global side effects like incrementing a counter will increment multiple
times.

You would see the same with plain tex syntax \newcounter\foo.... if you use
inside tabularx.

latex counters have a reset mechanism (designed for use with restoring
counters after \include, mostly) tabularx uses this to restore all
counters at the start of every trial setting.

\hfuzz is \maxdimen in trials so you can avoid incremengting counters
during trials with

\ifdim\hfuzz<\maxdimen
...

but sometimes your code needs to increment and then restore, which is a
bit more work.

David

David

________________________________

The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is:

Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Microsoft Office 365.

________________________________