newcommand distorts qrcode

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite












I have found that the output of qrcode is distorted if the qrcode is placed inside of command in latex. Here below there is a MWE showing 2 qrcodes which are actually the same, one produced from within a newcommand called contact and one produced without it. I'm using the qrcode package.



The difference is noticeable and actually when I scan both codes, the one on the left is recognized as a contact and the other is not. This is the MWE:



documentclass[border=1cm]standalone
usepackageqrcode


newcommandcontact
qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD




begindocument

qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD



contact
enddocument


And the difference is actually visible. The one on the right is distorted:



QR Codes: On the left qrcode produced without newcommand. On the right, the qrcode produced without it



I have tested this behavior under Debian Buster, both with Xelatex and Pdflatex. Both exhibit the same behavior. The question is in this case, is there anyway to solve this distortion? What is actually causing this?



Best regards,



Ch.










share|improve this question

















  • 1




    The qrcode command does several changes in the category code of characters and also to the endline character. These cannot be applied if qrcode... is in the argument to another command (such as newcommand).
    – egreg
    37 mins ago






  • 1




    From the manual (p.5): As with all verbatim modes, however, because T E X irrevocably sets catcodes when it first encounters characters, this will not work if the qrcode macro is contained in another macro. However, that comment refers to "special characters"...and I don't see them in your input.
    – Steven B. Segletes
    34 mins ago















up vote
6
down vote

favorite












I have found that the output of qrcode is distorted if the qrcode is placed inside of command in latex. Here below there is a MWE showing 2 qrcodes which are actually the same, one produced from within a newcommand called contact and one produced without it. I'm using the qrcode package.



The difference is noticeable and actually when I scan both codes, the one on the left is recognized as a contact and the other is not. This is the MWE:



documentclass[border=1cm]standalone
usepackageqrcode


newcommandcontact
qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD




begindocument

qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD



contact
enddocument


And the difference is actually visible. The one on the right is distorted:



QR Codes: On the left qrcode produced without newcommand. On the right, the qrcode produced without it



I have tested this behavior under Debian Buster, both with Xelatex and Pdflatex. Both exhibit the same behavior. The question is in this case, is there anyway to solve this distortion? What is actually causing this?



Best regards,



Ch.










share|improve this question

















  • 1




    The qrcode command does several changes in the category code of characters and also to the endline character. These cannot be applied if qrcode... is in the argument to another command (such as newcommand).
    – egreg
    37 mins ago






  • 1




    From the manual (p.5): As with all verbatim modes, however, because T E X irrevocably sets catcodes when it first encounters characters, this will not work if the qrcode macro is contained in another macro. However, that comment refers to "special characters"...and I don't see them in your input.
    – Steven B. Segletes
    34 mins ago













up vote
6
down vote

favorite









up vote
6
down vote

favorite











I have found that the output of qrcode is distorted if the qrcode is placed inside of command in latex. Here below there is a MWE showing 2 qrcodes which are actually the same, one produced from within a newcommand called contact and one produced without it. I'm using the qrcode package.



The difference is noticeable and actually when I scan both codes, the one on the left is recognized as a contact and the other is not. This is the MWE:



documentclass[border=1cm]standalone
usepackageqrcode


newcommandcontact
qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD




begindocument

qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD



contact
enddocument


And the difference is actually visible. The one on the right is distorted:



QR Codes: On the left qrcode produced without newcommand. On the right, the qrcode produced without it



I have tested this behavior under Debian Buster, both with Xelatex and Pdflatex. Both exhibit the same behavior. The question is in this case, is there anyway to solve this distortion? What is actually causing this?



Best regards,



Ch.










share|improve this question













I have found that the output of qrcode is distorted if the qrcode is placed inside of command in latex. Here below there is a MWE showing 2 qrcodes which are actually the same, one produced from within a newcommand called contact and one produced without it. I'm using the qrcode package.



The difference is noticeable and actually when I scan both codes, the one on the left is recognized as a contact and the other is not. This is the MWE:



documentclass[border=1cm]standalone
usepackageqrcode


newcommandcontact
qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD




begindocument

qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD



contact
enddocument


And the difference is actually visible. The one on the right is distorted:



QR Codes: On the left qrcode produced without newcommand. On the right, the qrcode produced without it



I have tested this behavior under Debian Buster, both with Xelatex and Pdflatex. Both exhibit the same behavior. The question is in this case, is there anyway to solve this distortion? What is actually causing this?



Best regards,



Ch.







macros qrcode






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 51 mins ago









Charlie

551312




551312







  • 1




    The qrcode command does several changes in the category code of characters and also to the endline character. These cannot be applied if qrcode... is in the argument to another command (such as newcommand).
    – egreg
    37 mins ago






  • 1




    From the manual (p.5): As with all verbatim modes, however, because T E X irrevocably sets catcodes when it first encounters characters, this will not work if the qrcode macro is contained in another macro. However, that comment refers to "special characters"...and I don't see them in your input.
    – Steven B. Segletes
    34 mins ago













  • 1




    The qrcode command does several changes in the category code of characters and also to the endline character. These cannot be applied if qrcode... is in the argument to another command (such as newcommand).
    – egreg
    37 mins ago






  • 1




    From the manual (p.5): As with all verbatim modes, however, because T E X irrevocably sets catcodes when it first encounters characters, this will not work if the qrcode macro is contained in another macro. However, that comment refers to "special characters"...and I don't see them in your input.
    – Steven B. Segletes
    34 mins ago








1




1




The qrcode command does several changes in the category code of characters and also to the endline character. These cannot be applied if qrcode... is in the argument to another command (such as newcommand).
– egreg
37 mins ago




The qrcode command does several changes in the category code of characters and also to the endline character. These cannot be applied if qrcode... is in the argument to another command (such as newcommand).
– egreg
37 mins ago




1




1




From the manual (p.5): As with all verbatim modes, however, because T E X irrevocably sets catcodes when it first encounters characters, this will not work if the qrcode macro is contained in another macro. However, that comment refers to "special characters"...and I don't see them in your input.
– Steven B. Segletes
34 mins ago





From the manual (p.5): As with all verbatim modes, however, because T E X irrevocably sets catcodes when it first encounters characters, this will not work if the qrcode macro is contained in another macro. However, that comment refers to "special characters"...and I don't see them in your input.
– Steven B. Segletes
34 mins ago











1 Answer
1






active

oldest

votes

















up vote
6
down vote













To quote the QR-code documentation:




As with all verbatim modes, however, because TEX irrevocably sets
catcodes when it first encounters characters, this will not work if
the qrcode macro is contained in another macro. If you call qrcode
inside an fbox or a marginpar, for example, and if your URL contains
one of those special characters, you will either encounter error
messages or (worse, because it is undetectable to the naked eye) have
the wrong QR code typeset. In this scenario, you can still include any
of the characters #$&^_~% by escaping them with an extra
backslash; so long as they eventually pass unexpanded to qrcode, they
will produce the correct QR code. A line break may be obtained with
?.




So it is caused by the line breaks and the spaces (the indention). You can fix it by replacing the line breaks with ?.



An example with identical barcodes:



documentclass[border=1cm]standalone
usepackageqrcode


newcommandcontact
qrcode?%
BEGIN:VCARD?%
VERSION:4.0?%
EMAIL:john.doe@doe.net?%
FN:John Doe?%
N:Doe;John;;;?%
TEL;TYPE=home:123456789?%
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d?%
URL:www.doe.net?%
END:VCARD?%




begindocument

qrcode
BEGIN:VCARD
VERSION:4.0
EMAIL:john.doe@doe.net
FN:John Doe
N:Doe;John;;;
TEL;TYPE=home:123456789
UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
URL:www.doe.net
END:VCARD



contact
enddocument


enter image description here






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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f451286%2fnewcommand-distorts-qrcode%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    6
    down vote













    To quote the QR-code documentation:




    As with all verbatim modes, however, because TEX irrevocably sets
    catcodes when it first encounters characters, this will not work if
    the qrcode macro is contained in another macro. If you call qrcode
    inside an fbox or a marginpar, for example, and if your URL contains
    one of those special characters, you will either encounter error
    messages or (worse, because it is undetectable to the naked eye) have
    the wrong QR code typeset. In this scenario, you can still include any
    of the characters #$&^_~% by escaping them with an extra
    backslash; so long as they eventually pass unexpanded to qrcode, they
    will produce the correct QR code. A line break may be obtained with
    ?.




    So it is caused by the line breaks and the spaces (the indention). You can fix it by replacing the line breaks with ?.



    An example with identical barcodes:



    documentclass[border=1cm]standalone
    usepackageqrcode


    newcommandcontact
    qrcode?%
    BEGIN:VCARD?%
    VERSION:4.0?%
    EMAIL:john.doe@doe.net?%
    FN:John Doe?%
    N:Doe;John;;;?%
    TEL;TYPE=home:123456789?%
    UID:8cbddd73-d45d-45ad-a1e4-9587984e880d?%
    URL:www.doe.net?%
    END:VCARD?%




    begindocument

    qrcode
    BEGIN:VCARD
    VERSION:4.0
    EMAIL:john.doe@doe.net
    FN:John Doe
    N:Doe;John;;;
    TEL;TYPE=home:123456789
    UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
    URL:www.doe.net
    END:VCARD



    contact
    enddocument


    enter image description here






    share|improve this answer
























      up vote
      6
      down vote













      To quote the QR-code documentation:




      As with all verbatim modes, however, because TEX irrevocably sets
      catcodes when it first encounters characters, this will not work if
      the qrcode macro is contained in another macro. If you call qrcode
      inside an fbox or a marginpar, for example, and if your URL contains
      one of those special characters, you will either encounter error
      messages or (worse, because it is undetectable to the naked eye) have
      the wrong QR code typeset. In this scenario, you can still include any
      of the characters #$&^_~% by escaping them with an extra
      backslash; so long as they eventually pass unexpanded to qrcode, they
      will produce the correct QR code. A line break may be obtained with
      ?.




      So it is caused by the line breaks and the spaces (the indention). You can fix it by replacing the line breaks with ?.



      An example with identical barcodes:



      documentclass[border=1cm]standalone
      usepackageqrcode


      newcommandcontact
      qrcode?%
      BEGIN:VCARD?%
      VERSION:4.0?%
      EMAIL:john.doe@doe.net?%
      FN:John Doe?%
      N:Doe;John;;;?%
      TEL;TYPE=home:123456789?%
      UID:8cbddd73-d45d-45ad-a1e4-9587984e880d?%
      URL:www.doe.net?%
      END:VCARD?%




      begindocument

      qrcode
      BEGIN:VCARD
      VERSION:4.0
      EMAIL:john.doe@doe.net
      FN:John Doe
      N:Doe;John;;;
      TEL;TYPE=home:123456789
      UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
      URL:www.doe.net
      END:VCARD



      contact
      enddocument


      enter image description here






      share|improve this answer






















        up vote
        6
        down vote










        up vote
        6
        down vote









        To quote the QR-code documentation:




        As with all verbatim modes, however, because TEX irrevocably sets
        catcodes when it first encounters characters, this will not work if
        the qrcode macro is contained in another macro. If you call qrcode
        inside an fbox or a marginpar, for example, and if your URL contains
        one of those special characters, you will either encounter error
        messages or (worse, because it is undetectable to the naked eye) have
        the wrong QR code typeset. In this scenario, you can still include any
        of the characters #$&^_~% by escaping them with an extra
        backslash; so long as they eventually pass unexpanded to qrcode, they
        will produce the correct QR code. A line break may be obtained with
        ?.




        So it is caused by the line breaks and the spaces (the indention). You can fix it by replacing the line breaks with ?.



        An example with identical barcodes:



        documentclass[border=1cm]standalone
        usepackageqrcode


        newcommandcontact
        qrcode?%
        BEGIN:VCARD?%
        VERSION:4.0?%
        EMAIL:john.doe@doe.net?%
        FN:John Doe?%
        N:Doe;John;;;?%
        TEL;TYPE=home:123456789?%
        UID:8cbddd73-d45d-45ad-a1e4-9587984e880d?%
        URL:www.doe.net?%
        END:VCARD?%




        begindocument

        qrcode
        BEGIN:VCARD
        VERSION:4.0
        EMAIL:john.doe@doe.net
        FN:John Doe
        N:Doe;John;;;
        TEL;TYPE=home:123456789
        UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
        URL:www.doe.net
        END:VCARD



        contact
        enddocument


        enter image description here






        share|improve this answer












        To quote the QR-code documentation:




        As with all verbatim modes, however, because TEX irrevocably sets
        catcodes when it first encounters characters, this will not work if
        the qrcode macro is contained in another macro. If you call qrcode
        inside an fbox or a marginpar, for example, and if your URL contains
        one of those special characters, you will either encounter error
        messages or (worse, because it is undetectable to the naked eye) have
        the wrong QR code typeset. In this scenario, you can still include any
        of the characters #$&^_~% by escaping them with an extra
        backslash; so long as they eventually pass unexpanded to qrcode, they
        will produce the correct QR code. A line break may be obtained with
        ?.




        So it is caused by the line breaks and the spaces (the indention). You can fix it by replacing the line breaks with ?.



        An example with identical barcodes:



        documentclass[border=1cm]standalone
        usepackageqrcode


        newcommandcontact
        qrcode?%
        BEGIN:VCARD?%
        VERSION:4.0?%
        EMAIL:john.doe@doe.net?%
        FN:John Doe?%
        N:Doe;John;;;?%
        TEL;TYPE=home:123456789?%
        UID:8cbddd73-d45d-45ad-a1e4-9587984e880d?%
        URL:www.doe.net?%
        END:VCARD?%




        begindocument

        qrcode
        BEGIN:VCARD
        VERSION:4.0
        EMAIL:john.doe@doe.net
        FN:John Doe
        N:Doe;John;;;
        TEL;TYPE=home:123456789
        UID:8cbddd73-d45d-45ad-a1e4-9587984e880d
        URL:www.doe.net
        END:VCARD



        contact
        enddocument


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 31 mins ago









        Marcel Krüger

        10.4k11032




        10.4k11032



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f451286%2fnewcommand-distorts-qrcode%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke