3

I'm trying to get a counter to work, called \l__ioiooiioio_args_second_int in the example below, and I've declared to increment at each loop through \int_incr:N \l__ioiooiioio_step_int, but apparently the counter stays put at zero (can be seen by controlling \int_compare:nT{\l__ioiooiioio_step_int = 0}{\hyperlink{doc.rc.#1}{$\rightarrow$}, which apparently is only true for \l__ioiooiioio_step_int=0. Apparently this is always the case. Why isn't the value of the counter increasing?

\documentclass{article}

\usepackage{xparse} \usepackage{longtable} \usepackage{multirow} \usepackage{hyperref}

\ExplSyntaxOn

\NewDocumentCommand{\mymacro}{ m m }  
 {   
  \ioiooiioio_setargs:nn { #1 } { #2 }   
  \ioiooiioio_print:n   
 }

\seq_new:N \l__ioiooiioio_first_col_seq 
\seq_new:N \l__ioiooiioio_second_col_seq 
\tl_new:N \l__ioiooiioio_table_body_tl 
\int_new:N \l__ioiooiioio_step_int 
\int_new:N \l__ioiooiioio_args_int

\cs_new_protected:Npn \ioiooiioio_setargs:nn #1 #2  
 {   
  \seq_set_split:Nnn \l__ioiooiioio_first_col_seq { , } { #1 }   
  \seq_set_split:Nnn \l__ioiooiioio_second_col_seq { , } { #2 }   
  \tl_clear:N \l__ioiooiioio_table_body_tl   
  \int_zero:N \l__ioiooiioio_step_int   
  \int_set:Nn \l__ioiooiioio_args_int { \seq_count:N \l__ioiooiioio_first_col_seq }
  \seq_mapthread_function:NNN
       \l__ioiooiioio_first_col_seq
       \l__ioiooiioio_second_col_seq
       \__ioiooiioio_fill_body:nn  
 }

\cs_new_protected:Npn \__ioiooiioio_fill_body:nn #1 #2  
 {
  \int_incr:N \l__ioiooiioio_step_int   
  \tl_put_right:Nn \l__ioiooiioio_table_body_tl {  & #1 & #2 & 
  \int_compare:nT{\l__ioiooiioio_step_int = 0}{\hyperlink{doc.rc.#1}{$\rightarrow$}}
  \\}  
 }

\cs_new_protected:Npn \ioiooiioio_print:n   
 {  
  \multirow{ \l__ioiooiioio_args_int}{*}{\seq_item:Nn \l__ioiooiioio_first_col_seq { 1 }} 
  \l__ioiooiioio_table_body_tl    
 } 
\ExplSyntaxOff

\begin{document}

\begin{longtable}{cccc} 
\mymacro{this is a test,this,is a,test}{now its,not a,test,anymore} 
\end{longtable}

\end{document}
  • By the way if \ioiooiioio_print:n does not have an argument, it should be \ioiooiioio_print:. – Manuel May 30 '14 at 7:48
  • @Manuel Yep, and it should be \cs_new_protected:Nn because there are no parameters to be given, right? – 1010011010 May 30 '14 at 8:28
5

I'm not sure exactly what you're trying to accomplish (which row do you want to put the hyperlink in?), but the main problem is not with the counter, it's that you're not expanding the test at the right time. Instead of expanding at the point where you're putting together the table body, the test expands within the cell of the table, and by then the counter has already been reset.

What you want is

\cs_new_protected:Npn \__ioiooiioio_fill_body:nn #1 #2
  {
    \int_incr:N \l__ioiooiioio_step_int
    \tl_put_right:Nn \l__ioiooiioio_table_body_tl { & #1 & #2 & }
    \int_compare:nT { \l__ioiooiioio_step_int = ROW-NUMBER-GOES-HERE }
      {
        \tl_put_right:Nn \l__ioiooiioio_table_body_tl 
          { 
            \hyperlink { doc.rc.#1 } { $ \rightarrow $ } 
          }
      }
    \tl_put_right:Nn \l__ioiooiioio_table_body_tl { \\ }
  }

Notice also that if you test whether \l__ioiooiioio_step_int equals zero, that test will never come out true because you've incremented your counter right before the test. If you want the hyperlink in the first row, you should test whether the counter is at one, not zero.

Also, since the printing command doesn't take any arguments, it should be \ioiooiioio_print:, not \ioiooiioio_print:n.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.