How to reliably check if a document variable is not empty in ConTeXt?











up vote
3
down vote

favorite












Consider the following MWE:



startdocument[title=]
doifemptyvariableelse{document}{title}{True}{documentvariable{title}}
Test
stopdocument


So basically I have a document with a title variable. Now I want to check if that variable is empty (doifemptyvariableelse). Instead of simply outputting the right branch and exiting the current code gobbles the next two tokens, which feels wrong.



Is there some easy approach to check whether a document variable is empty that does not gobble following tokens?










share|improve this question






















  • @Marco Well, I usually consult setup-en.pdf to see the available commands and it does not list doifdocumentvariable. The wiki also does not mention the new commands. Would you like to add an answer?
    – TeXnician
    Nov 18 at 16:19










  • Done. I can't for sure say why doifemptyvariable doesn't work in this case. It has something to do with how the argument is constructed, I believe. But I leave that part to the experts.
    – Marco
    Nov 18 at 16:31










  • a) doifemptyvariableelse doesn’t work because there is a bug (wrong number of arguments) for the TRUE case. b) The commands will be added to setup-en.pdf (If you miss a command in the document you can send a message to the ConTeXt mailing list or the author of the document).
    – Wolfgang Schuster
    Nov 18 at 22:34















up vote
3
down vote

favorite












Consider the following MWE:



startdocument[title=]
doifemptyvariableelse{document}{title}{True}{documentvariable{title}}
Test
stopdocument


So basically I have a document with a title variable. Now I want to check if that variable is empty (doifemptyvariableelse). Instead of simply outputting the right branch and exiting the current code gobbles the next two tokens, which feels wrong.



Is there some easy approach to check whether a document variable is empty that does not gobble following tokens?










share|improve this question






















  • @Marco Well, I usually consult setup-en.pdf to see the available commands and it does not list doifdocumentvariable. The wiki also does not mention the new commands. Would you like to add an answer?
    – TeXnician
    Nov 18 at 16:19










  • Done. I can't for sure say why doifemptyvariable doesn't work in this case. It has something to do with how the argument is constructed, I believe. But I leave that part to the experts.
    – Marco
    Nov 18 at 16:31










  • a) doifemptyvariableelse doesn’t work because there is a bug (wrong number of arguments) for the TRUE case. b) The commands will be added to setup-en.pdf (If you miss a command in the document you can send a message to the ConTeXt mailing list or the author of the document).
    – Wolfgang Schuster
    Nov 18 at 22:34













up vote
3
down vote

favorite









up vote
3
down vote

favorite











Consider the following MWE:



startdocument[title=]
doifemptyvariableelse{document}{title}{True}{documentvariable{title}}
Test
stopdocument


So basically I have a document with a title variable. Now I want to check if that variable is empty (doifemptyvariableelse). Instead of simply outputting the right branch and exiting the current code gobbles the next two tokens, which feels wrong.



Is there some easy approach to check whether a document variable is empty that does not gobble following tokens?










share|improve this question













Consider the following MWE:



startdocument[title=]
doifemptyvariableelse{document}{title}{True}{documentvariable{title}}
Test
stopdocument


So basically I have a document with a title variable. Now I want to check if that variable is empty (doifemptyvariableelse). Instead of simply outputting the right branch and exiting the current code gobbles the next two tokens, which feels wrong.



Is there some easy approach to check whether a document variable is empty that does not gobble following tokens?







context






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 at 15:23









TeXnician

23.4k62984




23.4k62984












  • @Marco Well, I usually consult setup-en.pdf to see the available commands and it does not list doifdocumentvariable. The wiki also does not mention the new commands. Would you like to add an answer?
    – TeXnician
    Nov 18 at 16:19










  • Done. I can't for sure say why doifemptyvariable doesn't work in this case. It has something to do with how the argument is constructed, I believe. But I leave that part to the experts.
    – Marco
    Nov 18 at 16:31










  • a) doifemptyvariableelse doesn’t work because there is a bug (wrong number of arguments) for the TRUE case. b) The commands will be added to setup-en.pdf (If you miss a command in the document you can send a message to the ConTeXt mailing list or the author of the document).
    – Wolfgang Schuster
    Nov 18 at 22:34


















  • @Marco Well, I usually consult setup-en.pdf to see the available commands and it does not list doifdocumentvariable. The wiki also does not mention the new commands. Would you like to add an answer?
    – TeXnician
    Nov 18 at 16:19










  • Done. I can't for sure say why doifemptyvariable doesn't work in this case. It has something to do with how the argument is constructed, I believe. But I leave that part to the experts.
    – Marco
    Nov 18 at 16:31










  • a) doifemptyvariableelse doesn’t work because there is a bug (wrong number of arguments) for the TRUE case. b) The commands will be added to setup-en.pdf (If you miss a command in the document you can send a message to the ConTeXt mailing list or the author of the document).
    – Wolfgang Schuster
    Nov 18 at 22:34
















@Marco Well, I usually consult setup-en.pdf to see the available commands and it does not list doifdocumentvariable. The wiki also does not mention the new commands. Would you like to add an answer?
– TeXnician
Nov 18 at 16:19




@Marco Well, I usually consult setup-en.pdf to see the available commands and it does not list doifdocumentvariable. The wiki also does not mention the new commands. Would you like to add an answer?
– TeXnician
Nov 18 at 16:19












Done. I can't for sure say why doifemptyvariable doesn't work in this case. It has something to do with how the argument is constructed, I believe. But I leave that part to the experts.
– Marco
Nov 18 at 16:31




Done. I can't for sure say why doifemptyvariable doesn't work in this case. It has something to do with how the argument is constructed, I believe. But I leave that part to the experts.
– Marco
Nov 18 at 16:31












a) doifemptyvariableelse doesn’t work because there is a bug (wrong number of arguments) for the TRUE case. b) The commands will be added to setup-en.pdf (If you miss a command in the document you can send a message to the ConTeXt mailing list or the author of the document).
– Wolfgang Schuster
Nov 18 at 22:34




a) doifemptyvariableelse doesn’t work because there is a bug (wrong number of arguments) for the TRUE case. b) The commands will be added to setup-en.pdf (If you miss a command in the document you can send a message to the ConTeXt mailing list or the author of the document).
– Wolfgang Schuster
Nov 18 at 22:34










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










You can use doifdocumentvariableelse (defined in file-job.mkvi), which uses doifsomething. Example:



startdocument[title=]
doifdocumentvariableelse{title}{documentvariable{title}}{False}

%% is the same as:
%% doifsomethingelse{documentvariable{title}}{documentvariable{title}}{False}

Test
stopdocument





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',
    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%2f460607%2fhow-to-reliably-check-if-a-document-variable-is-not-empty-in-context%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    You can use doifdocumentvariableelse (defined in file-job.mkvi), which uses doifsomething. Example:



    startdocument[title=]
    doifdocumentvariableelse{title}{documentvariable{title}}{False}

    %% is the same as:
    %% doifsomethingelse{documentvariable{title}}{documentvariable{title}}{False}

    Test
    stopdocument





    share|improve this answer

























      up vote
      4
      down vote



      accepted










      You can use doifdocumentvariableelse (defined in file-job.mkvi), which uses doifsomething. Example:



      startdocument[title=]
      doifdocumentvariableelse{title}{documentvariable{title}}{False}

      %% is the same as:
      %% doifsomethingelse{documentvariable{title}}{documentvariable{title}}{False}

      Test
      stopdocument





      share|improve this answer























        up vote
        4
        down vote



        accepted







        up vote
        4
        down vote



        accepted






        You can use doifdocumentvariableelse (defined in file-job.mkvi), which uses doifsomething. Example:



        startdocument[title=]
        doifdocumentvariableelse{title}{documentvariable{title}}{False}

        %% is the same as:
        %% doifsomethingelse{documentvariable{title}}{documentvariable{title}}{False}

        Test
        stopdocument





        share|improve this answer












        You can use doifdocumentvariableelse (defined in file-job.mkvi), which uses doifsomething. Example:



        startdocument[title=]
        doifdocumentvariableelse{title}{documentvariable{title}}{False}

        %% is the same as:
        %% doifsomethingelse{documentvariable{title}}{documentvariable{title}}{False}

        Test
        stopdocument






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 at 16:29









        Marco

        23.9k26797




        23.9k26797






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460607%2fhow-to-reliably-check-if-a-document-variable-is-not-empty-in-context%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

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?