How to properly store the current value of int variable into a token list?Removing and storing the head of a token list/toksHow to count the frequency of a token in a token listGetting the current value of a global variable into a prop listLaTeX3 Create environment around token list variableOnly last value of a variable goes into psfrag functionWhat are the constituents of a LaTeX3 token list?How to handle a LaTeX3 token list as a list of tokens rather than as a list of items?How to create a local token list variable in LaTeX3?Latex3: multicolumn at the beginning of a token list produces an errorHow to use the token list variable from prop_get

Magical Modulo Squares

What should I use to get rid of some kind of weed in my onions

I'm attempting to understand my 401k match and how much I need to contribute to maximize the match

Why doesn't increasing the temperature of something like wood or paper set them on fire?

Should one save up to purchase a house/condo or maximize their 401(k) first?

Every group the homology of some space?

Can you turn music upside down?

Crime rates in a post-scarcity economy

While drilling into kitchen wall, hit a wire - any advice?

Why are thrust reversers not used down to taxi speeds?

History: Per Leviticus 19:27 would the apostles have had corner locks ala Hassidim today?

Is this strange Morse signal type common?

What's the difference between "ricochet" and "bounce"?

Names of the Six Tastes

Is the tensor product (of vector spaces) commutative?

Examples where existence is harder than evaluation

How is it believable that Euron could so easily pull off this ambush?

Exactly which act of bravery are Luke and Han awarded a medal for?

My parents are Afghan

What happens when the drag force exceeds the weight of an object falling into earth?

Can radiation block all wireless communications?

Was Mohammed the most popular first name for boys born in Berlin in 2018?

How to explain intravenous drug abuse to a 6-year-old?

Why did Ham the Chimp push levers?



How to properly store the current value of int variable into a token list?


Removing and storing the head of a token list/toksHow to count the frequency of a token in a token listGetting the current value of a global variable into a prop listLaTeX3 Create environment around token list variableOnly last value of a variable goes into psfrag functionWhat are the constituents of a LaTeX3 token list?How to handle a LaTeX3 token list as a list of tokens rather than as a list of items?How to create a local token list variable in LaTeX3?Latex3: multicolumn at the beginning of a token list produces an errorHow to use the token list variable from prop_get













2















I have an volatile integer variable (counter) and at some point I wish to save its value to a token list (saved_counter).

If I save it with just tl_set, as soon as counter changes the value, this also changes the value of saved_counter, which is undesirable.



Example:



documentclassarticle
usepackage[utf8]inputenc
usepackagexparse

ExplSyntaxOn
int_zero_new:N counter % Set counter to 0.
tl_new:N saved_counter
ExplSyntaxOff

begindocument
ExplSyntaxOn
% Save C_0 in "saved_counter"
tl_set:Nn saved_counter C textsubscript thecounter

% Print the value of saved counter -> C_0
saved_counter

% Change the value of counter for whatever the reason.
int_incr:N counter

% Print the value of saved counter again -> C_1
saved_counter
ExplSyntaxOff
enddocument


I understand that there are no real variables in LaTeX and that everything's a macro, therefore, I understand why this is happening.



However, this seems like a common problem and there must be some convenient solution, like expanding/converting the value of counter to string and then assigning it to saved_counter.

Unfortunately, I am new to LaTeX and couldn't figure it out by myself.










share|improve this question






















  • You don't say, but do we just want the counter value or the 'extras' (the C, etc.). The answer by frougon assumes you do want the extras .... but if you don't, you can save the value directly.

    – Joseph Wright
    May 4 at 19:02











  • The same problem occurs when saving just the value. I added 'extras' because those 'extras' are my real use case and I wanted to be sure that offered answers work with it, not just with plain number.

    – Iskustvo
    May 4 at 19:10















2















I have an volatile integer variable (counter) and at some point I wish to save its value to a token list (saved_counter).

If I save it with just tl_set, as soon as counter changes the value, this also changes the value of saved_counter, which is undesirable.



Example:



documentclassarticle
usepackage[utf8]inputenc
usepackagexparse

ExplSyntaxOn
int_zero_new:N counter % Set counter to 0.
tl_new:N saved_counter
ExplSyntaxOff

begindocument
ExplSyntaxOn
% Save C_0 in "saved_counter"
tl_set:Nn saved_counter C textsubscript thecounter

% Print the value of saved counter -> C_0
saved_counter

% Change the value of counter for whatever the reason.
int_incr:N counter

% Print the value of saved counter again -> C_1
saved_counter
ExplSyntaxOff
enddocument


I understand that there are no real variables in LaTeX and that everything's a macro, therefore, I understand why this is happening.



However, this seems like a common problem and there must be some convenient solution, like expanding/converting the value of counter to string and then assigning it to saved_counter.

Unfortunately, I am new to LaTeX and couldn't figure it out by myself.










share|improve this question






















  • You don't say, but do we just want the counter value or the 'extras' (the C, etc.). The answer by frougon assumes you do want the extras .... but if you don't, you can save the value directly.

    – Joseph Wright
    May 4 at 19:02











  • The same problem occurs when saving just the value. I added 'extras' because those 'extras' are my real use case and I wanted to be sure that offered answers work with it, not just with plain number.

    – Iskustvo
    May 4 at 19:10













2












2








2








I have an volatile integer variable (counter) and at some point I wish to save its value to a token list (saved_counter).

If I save it with just tl_set, as soon as counter changes the value, this also changes the value of saved_counter, which is undesirable.



Example:



documentclassarticle
usepackage[utf8]inputenc
usepackagexparse

ExplSyntaxOn
int_zero_new:N counter % Set counter to 0.
tl_new:N saved_counter
ExplSyntaxOff

begindocument
ExplSyntaxOn
% Save C_0 in "saved_counter"
tl_set:Nn saved_counter C textsubscript thecounter

% Print the value of saved counter -> C_0
saved_counter

% Change the value of counter for whatever the reason.
int_incr:N counter

% Print the value of saved counter again -> C_1
saved_counter
ExplSyntaxOff
enddocument


I understand that there are no real variables in LaTeX and that everything's a macro, therefore, I understand why this is happening.



However, this seems like a common problem and there must be some convenient solution, like expanding/converting the value of counter to string and then assigning it to saved_counter.

Unfortunately, I am new to LaTeX and couldn't figure it out by myself.










share|improve this question














I have an volatile integer variable (counter) and at some point I wish to save its value to a token list (saved_counter).

If I save it with just tl_set, as soon as counter changes the value, this also changes the value of saved_counter, which is undesirable.



Example:



documentclassarticle
usepackage[utf8]inputenc
usepackagexparse

ExplSyntaxOn
int_zero_new:N counter % Set counter to 0.
tl_new:N saved_counter
ExplSyntaxOff

begindocument
ExplSyntaxOn
% Save C_0 in "saved_counter"
tl_set:Nn saved_counter C textsubscript thecounter

% Print the value of saved counter -> C_0
saved_counter

% Change the value of counter for whatever the reason.
int_incr:N counter

% Print the value of saved counter again -> C_1
saved_counter
ExplSyntaxOff
enddocument


I understand that there are no real variables in LaTeX and that everything's a macro, therefore, I understand why this is happening.



However, this seems like a common problem and there must be some convenient solution, like expanding/converting the value of counter to string and then assigning it to saved_counter.

Unfortunately, I am new to LaTeX and couldn't figure it out by myself.







latex3 token-lists variable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 4 at 18:20









IskustvoIskustvo

1303




1303












  • You don't say, but do we just want the counter value or the 'extras' (the C, etc.). The answer by frougon assumes you do want the extras .... but if you don't, you can save the value directly.

    – Joseph Wright
    May 4 at 19:02











  • The same problem occurs when saving just the value. I added 'extras' because those 'extras' are my real use case and I wanted to be sure that offered answers work with it, not just with plain number.

    – Iskustvo
    May 4 at 19:10

















  • You don't say, but do we just want the counter value or the 'extras' (the C, etc.). The answer by frougon assumes you do want the extras .... but if you don't, you can save the value directly.

    – Joseph Wright
    May 4 at 19:02











  • The same problem occurs when saving just the value. I added 'extras' because those 'extras' are my real use case and I wanted to be sure that offered answers work with it, not just with plain number.

    – Iskustvo
    May 4 at 19:10
















You don't say, but do we just want the counter value or the 'extras' (the C, etc.). The answer by frougon assumes you do want the extras .... but if you don't, you can save the value directly.

– Joseph Wright
May 4 at 19:02





You don't say, but do we just want the counter value or the 'extras' (the C, etc.). The answer by frougon assumes you do want the extras .... but if you don't, you can save the value directly.

– Joseph Wright
May 4 at 19:02













The same problem occurs when saving just the value. I added 'extras' because those 'extras' are my real use case and I wanted to be sure that offered answers work with it, not just with plain number.

– Iskustvo
May 4 at 19:10





The same problem occurs when saving just the value. I added 'extras' because those 'extras' are my real use case and I wanted to be sure that offered answers work with it, not just with plain number.

– Iskustvo
May 4 at 19:10










2 Answers
2






active

oldest

votes


















4














The problem with your code is that when you do:



tl_set:Nn saved_counter C textsubscript thecounter


the token list variable contains:



  • the C character token;

  • the textsubscript control sequence token;

  • an opening brace character token;

  • the the control sequence token;

  • the counter control sequence token;

  • a closing brace character token.

In particular, thecounter is not expanded in your saved token list. It gets expanded later, when you use the token list and it is absorbed by TeX token by token. This is why it reflects the value of the counter when your saved_counter is expanded—at the last moment.



The solution is to expand thecounter when you want to save the token list (I used a LaTeX3-ish way to print the counter using decimal notation as with LaTeX2e's arabic or TeX's number):



documentclassarticle
usepackage[utf8]inputenc
usepackagexparse

ExplSyntaxOn

int_zero_new:N g_my_counter_int % Set counter to 0.
tl_new:N g_my_saved_tl

cs_new_protected:Npn my_update_token_list:n #1

tl_gset:Nn g_my_saved_tl C textsubscript #1


cs_generate_variant:Nn my_update_token_list:n x

NewDocumentCommand myUpdateTokenList m

% The x-form eXpands the argument first
my_update_token_list:x int_to_arabic:n #1


ExplSyntaxOff

begindocument
ExplSyntaxOn
% Save the token list using the current counter value -> C_0
myUpdateTokenListg_my_counter_int

% Print the saved token list
tl_use:N g_my_saved_tl

% Change the counter value for whatever the reason.
int_gincr:N g_my_counter_int

% This is still the token list saved by myUpdateTokenList above, where
% the value 0 had been used.
tl_use:N g_my_saved_tl
ExplSyntaxOff
enddocument


I also adapted your code to be more LaTeX3-conventional (variable names) and used global incr/set functions for the counter and token list (depends on your application, but is more straightforward this way). I believe it would be cleaner to put ExplSyntaxOn stuff only inside the preamble. For this, you'd have to wrap all the LaTeX3 code inside user-oriented commands, as I did for myUpdateTokenList. This makes the LaTeX3 things accessible to LaTeX2e: via arguments passed to commands that you implement in the preamble under ExplSyntaxOn regime.






share|improve this answer




















  • 1





    I updated my code because myUpdateTokenList was always using g_my_counter_int instead of its argument. Of course, if the same counter should always be used, myUpdateTokenList could be made parameterless and hardcode g_my_counter_int in its definition.

    – frougon
    May 4 at 21:22


















2














The answer by frogon covers the approach best if you want to save not only the value itself but also additional material. There are however other ways.



I would probably just save the value in a second int:



documentclassarticle
usepackageexpl3
ExplSyntaxOn
int_new:N counter % Set counter to 0.
int_new:N l__iskustvo_saved_counter_int
ExplSyntaxOff

begindocument
ExplSyntaxOn
% Save C_0 in "saved_counter"
int_set_eq:NN l__iskustvo_saved_counter_int counter

% Print the value of saved counter -> C_0
int_use:N l__iskustvo_saved_counter_int

% Change the value of counter for whatever the reason.
int_incr:N counter

% Print the value of saved counter again -> C_1
int_use:N l__iskustvo_saved_counter_int
ExplSyntaxOff
enddocument


If you want to use a tl, you can save the value using V-type expansion



documentclassarticle
usepackageexpl3
ExplSyntaxOn
int_new:N counter % Set counter to 0.
tl_new:N l__iskustvo_saved_counter_tl
ExplSyntaxOff

begindocument
ExplSyntaxOn
% Save C_0 in "saved_counter"
tl_set:NV l__iskustvo_saved_counter_tl counter

% Print the value of saved counter -> C_0
l__iskustvo_saved_counter_tl

% Change the value of counter for whatever the reason.
int_incr:N counter

% Print the value of saved counter again -> C_1
l__iskustvo_saved_counter_tl
ExplSyntaxOff
enddocument





share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489195%2fhow-to-properly-store-the-current-value-of-int-variable-into-a-token-list%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    The problem with your code is that when you do:



    tl_set:Nn saved_counter C textsubscript thecounter


    the token list variable contains:



    • the C character token;

    • the textsubscript control sequence token;

    • an opening brace character token;

    • the the control sequence token;

    • the counter control sequence token;

    • a closing brace character token.

    In particular, thecounter is not expanded in your saved token list. It gets expanded later, when you use the token list and it is absorbed by TeX token by token. This is why it reflects the value of the counter when your saved_counter is expanded—at the last moment.



    The solution is to expand thecounter when you want to save the token list (I used a LaTeX3-ish way to print the counter using decimal notation as with LaTeX2e's arabic or TeX's number):



    documentclassarticle
    usepackage[utf8]inputenc
    usepackagexparse

    ExplSyntaxOn

    int_zero_new:N g_my_counter_int % Set counter to 0.
    tl_new:N g_my_saved_tl

    cs_new_protected:Npn my_update_token_list:n #1

    tl_gset:Nn g_my_saved_tl C textsubscript #1


    cs_generate_variant:Nn my_update_token_list:n x

    NewDocumentCommand myUpdateTokenList m

    % The x-form eXpands the argument first
    my_update_token_list:x int_to_arabic:n #1


    ExplSyntaxOff

    begindocument
    ExplSyntaxOn
    % Save the token list using the current counter value -> C_0
    myUpdateTokenListg_my_counter_int

    % Print the saved token list
    tl_use:N g_my_saved_tl

    % Change the counter value for whatever the reason.
    int_gincr:N g_my_counter_int

    % This is still the token list saved by myUpdateTokenList above, where
    % the value 0 had been used.
    tl_use:N g_my_saved_tl
    ExplSyntaxOff
    enddocument


    I also adapted your code to be more LaTeX3-conventional (variable names) and used global incr/set functions for the counter and token list (depends on your application, but is more straightforward this way). I believe it would be cleaner to put ExplSyntaxOn stuff only inside the preamble. For this, you'd have to wrap all the LaTeX3 code inside user-oriented commands, as I did for myUpdateTokenList. This makes the LaTeX3 things accessible to LaTeX2e: via arguments passed to commands that you implement in the preamble under ExplSyntaxOn regime.






    share|improve this answer




















    • 1





      I updated my code because myUpdateTokenList was always using g_my_counter_int instead of its argument. Of course, if the same counter should always be used, myUpdateTokenList could be made parameterless and hardcode g_my_counter_int in its definition.

      – frougon
      May 4 at 21:22















    4














    The problem with your code is that when you do:



    tl_set:Nn saved_counter C textsubscript thecounter


    the token list variable contains:



    • the C character token;

    • the textsubscript control sequence token;

    • an opening brace character token;

    • the the control sequence token;

    • the counter control sequence token;

    • a closing brace character token.

    In particular, thecounter is not expanded in your saved token list. It gets expanded later, when you use the token list and it is absorbed by TeX token by token. This is why it reflects the value of the counter when your saved_counter is expanded—at the last moment.



    The solution is to expand thecounter when you want to save the token list (I used a LaTeX3-ish way to print the counter using decimal notation as with LaTeX2e's arabic or TeX's number):



    documentclassarticle
    usepackage[utf8]inputenc
    usepackagexparse

    ExplSyntaxOn

    int_zero_new:N g_my_counter_int % Set counter to 0.
    tl_new:N g_my_saved_tl

    cs_new_protected:Npn my_update_token_list:n #1

    tl_gset:Nn g_my_saved_tl C textsubscript #1


    cs_generate_variant:Nn my_update_token_list:n x

    NewDocumentCommand myUpdateTokenList m

    % The x-form eXpands the argument first
    my_update_token_list:x int_to_arabic:n #1


    ExplSyntaxOff

    begindocument
    ExplSyntaxOn
    % Save the token list using the current counter value -> C_0
    myUpdateTokenListg_my_counter_int

    % Print the saved token list
    tl_use:N g_my_saved_tl

    % Change the counter value for whatever the reason.
    int_gincr:N g_my_counter_int

    % This is still the token list saved by myUpdateTokenList above, where
    % the value 0 had been used.
    tl_use:N g_my_saved_tl
    ExplSyntaxOff
    enddocument


    I also adapted your code to be more LaTeX3-conventional (variable names) and used global incr/set functions for the counter and token list (depends on your application, but is more straightforward this way). I believe it would be cleaner to put ExplSyntaxOn stuff only inside the preamble. For this, you'd have to wrap all the LaTeX3 code inside user-oriented commands, as I did for myUpdateTokenList. This makes the LaTeX3 things accessible to LaTeX2e: via arguments passed to commands that you implement in the preamble under ExplSyntaxOn regime.






    share|improve this answer




















    • 1





      I updated my code because myUpdateTokenList was always using g_my_counter_int instead of its argument. Of course, if the same counter should always be used, myUpdateTokenList could be made parameterless and hardcode g_my_counter_int in its definition.

      – frougon
      May 4 at 21:22













    4












    4








    4







    The problem with your code is that when you do:



    tl_set:Nn saved_counter C textsubscript thecounter


    the token list variable contains:



    • the C character token;

    • the textsubscript control sequence token;

    • an opening brace character token;

    • the the control sequence token;

    • the counter control sequence token;

    • a closing brace character token.

    In particular, thecounter is not expanded in your saved token list. It gets expanded later, when you use the token list and it is absorbed by TeX token by token. This is why it reflects the value of the counter when your saved_counter is expanded—at the last moment.



    The solution is to expand thecounter when you want to save the token list (I used a LaTeX3-ish way to print the counter using decimal notation as with LaTeX2e's arabic or TeX's number):



    documentclassarticle
    usepackage[utf8]inputenc
    usepackagexparse

    ExplSyntaxOn

    int_zero_new:N g_my_counter_int % Set counter to 0.
    tl_new:N g_my_saved_tl

    cs_new_protected:Npn my_update_token_list:n #1

    tl_gset:Nn g_my_saved_tl C textsubscript #1


    cs_generate_variant:Nn my_update_token_list:n x

    NewDocumentCommand myUpdateTokenList m

    % The x-form eXpands the argument first
    my_update_token_list:x int_to_arabic:n #1


    ExplSyntaxOff

    begindocument
    ExplSyntaxOn
    % Save the token list using the current counter value -> C_0
    myUpdateTokenListg_my_counter_int

    % Print the saved token list
    tl_use:N g_my_saved_tl

    % Change the counter value for whatever the reason.
    int_gincr:N g_my_counter_int

    % This is still the token list saved by myUpdateTokenList above, where
    % the value 0 had been used.
    tl_use:N g_my_saved_tl
    ExplSyntaxOff
    enddocument


    I also adapted your code to be more LaTeX3-conventional (variable names) and used global incr/set functions for the counter and token list (depends on your application, but is more straightforward this way). I believe it would be cleaner to put ExplSyntaxOn stuff only inside the preamble. For this, you'd have to wrap all the LaTeX3 code inside user-oriented commands, as I did for myUpdateTokenList. This makes the LaTeX3 things accessible to LaTeX2e: via arguments passed to commands that you implement in the preamble under ExplSyntaxOn regime.






    share|improve this answer















    The problem with your code is that when you do:



    tl_set:Nn saved_counter C textsubscript thecounter


    the token list variable contains:



    • the C character token;

    • the textsubscript control sequence token;

    • an opening brace character token;

    • the the control sequence token;

    • the counter control sequence token;

    • a closing brace character token.

    In particular, thecounter is not expanded in your saved token list. It gets expanded later, when you use the token list and it is absorbed by TeX token by token. This is why it reflects the value of the counter when your saved_counter is expanded—at the last moment.



    The solution is to expand thecounter when you want to save the token list (I used a LaTeX3-ish way to print the counter using decimal notation as with LaTeX2e's arabic or TeX's number):



    documentclassarticle
    usepackage[utf8]inputenc
    usepackagexparse

    ExplSyntaxOn

    int_zero_new:N g_my_counter_int % Set counter to 0.
    tl_new:N g_my_saved_tl

    cs_new_protected:Npn my_update_token_list:n #1

    tl_gset:Nn g_my_saved_tl C textsubscript #1


    cs_generate_variant:Nn my_update_token_list:n x

    NewDocumentCommand myUpdateTokenList m

    % The x-form eXpands the argument first
    my_update_token_list:x int_to_arabic:n #1


    ExplSyntaxOff

    begindocument
    ExplSyntaxOn
    % Save the token list using the current counter value -> C_0
    myUpdateTokenListg_my_counter_int

    % Print the saved token list
    tl_use:N g_my_saved_tl

    % Change the counter value for whatever the reason.
    int_gincr:N g_my_counter_int

    % This is still the token list saved by myUpdateTokenList above, where
    % the value 0 had been used.
    tl_use:N g_my_saved_tl
    ExplSyntaxOff
    enddocument


    I also adapted your code to be more LaTeX3-conventional (variable names) and used global incr/set functions for the counter and token list (depends on your application, but is more straightforward this way). I believe it would be cleaner to put ExplSyntaxOn stuff only inside the preamble. For this, you'd have to wrap all the LaTeX3 code inside user-oriented commands, as I did for myUpdateTokenList. This makes the LaTeX3 things accessible to LaTeX2e: via arguments passed to commands that you implement in the preamble under ExplSyntaxOn regime.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 4 at 21:18

























    answered May 4 at 18:59









    frougonfrougon

    1,291712




    1,291712







    • 1





      I updated my code because myUpdateTokenList was always using g_my_counter_int instead of its argument. Of course, if the same counter should always be used, myUpdateTokenList could be made parameterless and hardcode g_my_counter_int in its definition.

      – frougon
      May 4 at 21:22












    • 1





      I updated my code because myUpdateTokenList was always using g_my_counter_int instead of its argument. Of course, if the same counter should always be used, myUpdateTokenList could be made parameterless and hardcode g_my_counter_int in its definition.

      – frougon
      May 4 at 21:22







    1




    1





    I updated my code because myUpdateTokenList was always using g_my_counter_int instead of its argument. Of course, if the same counter should always be used, myUpdateTokenList could be made parameterless and hardcode g_my_counter_int in its definition.

    – frougon
    May 4 at 21:22





    I updated my code because myUpdateTokenList was always using g_my_counter_int instead of its argument. Of course, if the same counter should always be used, myUpdateTokenList could be made parameterless and hardcode g_my_counter_int in its definition.

    – frougon
    May 4 at 21:22











    2














    The answer by frogon covers the approach best if you want to save not only the value itself but also additional material. There are however other ways.



    I would probably just save the value in a second int:



    documentclassarticle
    usepackageexpl3
    ExplSyntaxOn
    int_new:N counter % Set counter to 0.
    int_new:N l__iskustvo_saved_counter_int
    ExplSyntaxOff

    begindocument
    ExplSyntaxOn
    % Save C_0 in "saved_counter"
    int_set_eq:NN l__iskustvo_saved_counter_int counter

    % Print the value of saved counter -> C_0
    int_use:N l__iskustvo_saved_counter_int

    % Change the value of counter for whatever the reason.
    int_incr:N counter

    % Print the value of saved counter again -> C_1
    int_use:N l__iskustvo_saved_counter_int
    ExplSyntaxOff
    enddocument


    If you want to use a tl, you can save the value using V-type expansion



    documentclassarticle
    usepackageexpl3
    ExplSyntaxOn
    int_new:N counter % Set counter to 0.
    tl_new:N l__iskustvo_saved_counter_tl
    ExplSyntaxOff

    begindocument
    ExplSyntaxOn
    % Save C_0 in "saved_counter"
    tl_set:NV l__iskustvo_saved_counter_tl counter

    % Print the value of saved counter -> C_0
    l__iskustvo_saved_counter_tl

    % Change the value of counter for whatever the reason.
    int_incr:N counter

    % Print the value of saved counter again -> C_1
    l__iskustvo_saved_counter_tl
    ExplSyntaxOff
    enddocument





    share|improve this answer



























      2














      The answer by frogon covers the approach best if you want to save not only the value itself but also additional material. There are however other ways.



      I would probably just save the value in a second int:



      documentclassarticle
      usepackageexpl3
      ExplSyntaxOn
      int_new:N counter % Set counter to 0.
      int_new:N l__iskustvo_saved_counter_int
      ExplSyntaxOff

      begindocument
      ExplSyntaxOn
      % Save C_0 in "saved_counter"
      int_set_eq:NN l__iskustvo_saved_counter_int counter

      % Print the value of saved counter -> C_0
      int_use:N l__iskustvo_saved_counter_int

      % Change the value of counter for whatever the reason.
      int_incr:N counter

      % Print the value of saved counter again -> C_1
      int_use:N l__iskustvo_saved_counter_int
      ExplSyntaxOff
      enddocument


      If you want to use a tl, you can save the value using V-type expansion



      documentclassarticle
      usepackageexpl3
      ExplSyntaxOn
      int_new:N counter % Set counter to 0.
      tl_new:N l__iskustvo_saved_counter_tl
      ExplSyntaxOff

      begindocument
      ExplSyntaxOn
      % Save C_0 in "saved_counter"
      tl_set:NV l__iskustvo_saved_counter_tl counter

      % Print the value of saved counter -> C_0
      l__iskustvo_saved_counter_tl

      % Change the value of counter for whatever the reason.
      int_incr:N counter

      % Print the value of saved counter again -> C_1
      l__iskustvo_saved_counter_tl
      ExplSyntaxOff
      enddocument





      share|improve this answer

























        2












        2








        2







        The answer by frogon covers the approach best if you want to save not only the value itself but also additional material. There are however other ways.



        I would probably just save the value in a second int:



        documentclassarticle
        usepackageexpl3
        ExplSyntaxOn
        int_new:N counter % Set counter to 0.
        int_new:N l__iskustvo_saved_counter_int
        ExplSyntaxOff

        begindocument
        ExplSyntaxOn
        % Save C_0 in "saved_counter"
        int_set_eq:NN l__iskustvo_saved_counter_int counter

        % Print the value of saved counter -> C_0
        int_use:N l__iskustvo_saved_counter_int

        % Change the value of counter for whatever the reason.
        int_incr:N counter

        % Print the value of saved counter again -> C_1
        int_use:N l__iskustvo_saved_counter_int
        ExplSyntaxOff
        enddocument


        If you want to use a tl, you can save the value using V-type expansion



        documentclassarticle
        usepackageexpl3
        ExplSyntaxOn
        int_new:N counter % Set counter to 0.
        tl_new:N l__iskustvo_saved_counter_tl
        ExplSyntaxOff

        begindocument
        ExplSyntaxOn
        % Save C_0 in "saved_counter"
        tl_set:NV l__iskustvo_saved_counter_tl counter

        % Print the value of saved counter -> C_0
        l__iskustvo_saved_counter_tl

        % Change the value of counter for whatever the reason.
        int_incr:N counter

        % Print the value of saved counter again -> C_1
        l__iskustvo_saved_counter_tl
        ExplSyntaxOff
        enddocument





        share|improve this answer













        The answer by frogon covers the approach best if you want to save not only the value itself but also additional material. There are however other ways.



        I would probably just save the value in a second int:



        documentclassarticle
        usepackageexpl3
        ExplSyntaxOn
        int_new:N counter % Set counter to 0.
        int_new:N l__iskustvo_saved_counter_int
        ExplSyntaxOff

        begindocument
        ExplSyntaxOn
        % Save C_0 in "saved_counter"
        int_set_eq:NN l__iskustvo_saved_counter_int counter

        % Print the value of saved counter -> C_0
        int_use:N l__iskustvo_saved_counter_int

        % Change the value of counter for whatever the reason.
        int_incr:N counter

        % Print the value of saved counter again -> C_1
        int_use:N l__iskustvo_saved_counter_int
        ExplSyntaxOff
        enddocument


        If you want to use a tl, you can save the value using V-type expansion



        documentclassarticle
        usepackageexpl3
        ExplSyntaxOn
        int_new:N counter % Set counter to 0.
        tl_new:N l__iskustvo_saved_counter_tl
        ExplSyntaxOff

        begindocument
        ExplSyntaxOn
        % Save C_0 in "saved_counter"
        tl_set:NV l__iskustvo_saved_counter_tl counter

        % Print the value of saved counter -> C_0
        l__iskustvo_saved_counter_tl

        % Change the value of counter for whatever the reason.
        int_incr:N counter

        % Print the value of saved counter again -> C_1
        l__iskustvo_saved_counter_tl
        ExplSyntaxOff
        enddocument






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 4 at 19:17









        Joseph WrightJoseph Wright

        206k23567897




        206k23567897



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489195%2fhow-to-properly-store-the-current-value-of-int-variable-into-a-token-list%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?