Error creating a newcommand which uses hspace












4















None of my newcommand declarations work for hspace, with or without arguments; I use the latest MathJax with the general libraries. Attempts so far:



newcommand{hs}[1]{hspace{#1}}
newcommand{hs}[1]{hspace{{#1}}}
newcommand{hs}[1]{hspace{{#1}px}}
newcommand{hs1}{hspace{10px}}


I have a pageful of other newcommand declarations that work just fine, unsure what's failing here. Any remedy?










share|improve this question









New contributor




OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 5





    Welcome to TeX.SE! The command name has to be preceded by a backslash: newcommand{hs}[1]{hspace{#1}}. Add a backslash and it will work. The and third versions add braces that shouldn't be there, so they won't work. The fourth version won't work because numbers can't be in command names, and the first optional argument to newcommand can't be empty.

    – Phelype Oleinik
    2 days ago













  • Note that mathjax is not LaTeX so you should probably not expect any newcommand to work.

    – daleif
    2 days ago






  • 2





    @daleif newcommand works in MathJax.

    – egreg
    2 days ago











  • @PhelypeOleinik Excellent, it works - thanks. Feel free to post your response as an answer if you'd like the answer credit.

    – OverLordGoldDragon
    2 days ago











  • @egreg out of the box with no extra configuration?

    – daleif
    2 days ago
















4















None of my newcommand declarations work for hspace, with or without arguments; I use the latest MathJax with the general libraries. Attempts so far:



newcommand{hs}[1]{hspace{#1}}
newcommand{hs}[1]{hspace{{#1}}}
newcommand{hs}[1]{hspace{{#1}px}}
newcommand{hs1}{hspace{10px}}


I have a pageful of other newcommand declarations that work just fine, unsure what's failing here. Any remedy?










share|improve this question









New contributor




OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 5





    Welcome to TeX.SE! The command name has to be preceded by a backslash: newcommand{hs}[1]{hspace{#1}}. Add a backslash and it will work. The and third versions add braces that shouldn't be there, so they won't work. The fourth version won't work because numbers can't be in command names, and the first optional argument to newcommand can't be empty.

    – Phelype Oleinik
    2 days ago













  • Note that mathjax is not LaTeX so you should probably not expect any newcommand to work.

    – daleif
    2 days ago






  • 2





    @daleif newcommand works in MathJax.

    – egreg
    2 days ago











  • @PhelypeOleinik Excellent, it works - thanks. Feel free to post your response as an answer if you'd like the answer credit.

    – OverLordGoldDragon
    2 days ago











  • @egreg out of the box with no extra configuration?

    – daleif
    2 days ago














4












4








4








None of my newcommand declarations work for hspace, with or without arguments; I use the latest MathJax with the general libraries. Attempts so far:



newcommand{hs}[1]{hspace{#1}}
newcommand{hs}[1]{hspace{{#1}}}
newcommand{hs}[1]{hspace{{#1}px}}
newcommand{hs1}{hspace{10px}}


I have a pageful of other newcommand declarations that work just fine, unsure what's failing here. Any remedy?










share|improve this question









New contributor




OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












None of my newcommand declarations work for hspace, with or without arguments; I use the latest MathJax with the general libraries. Attempts so far:



newcommand{hs}[1]{hspace{#1}}
newcommand{hs}[1]{hspace{{#1}}}
newcommand{hs}[1]{hspace{{#1}px}}
newcommand{hs1}{hspace{10px}}


I have a pageful of other newcommand declarations that work just fine, unsure what's failing here. Any remedy?







spacing macros errors mathjax






share|improve this question









New contributor




OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Phelype Oleinik

22k54482




22k54482






New contributor




OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









OverLordGoldDragonOverLordGoldDragon

233




233




New contributor




OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






OverLordGoldDragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 5





    Welcome to TeX.SE! The command name has to be preceded by a backslash: newcommand{hs}[1]{hspace{#1}}. Add a backslash and it will work. The and third versions add braces that shouldn't be there, so they won't work. The fourth version won't work because numbers can't be in command names, and the first optional argument to newcommand can't be empty.

    – Phelype Oleinik
    2 days ago













  • Note that mathjax is not LaTeX so you should probably not expect any newcommand to work.

    – daleif
    2 days ago






  • 2





    @daleif newcommand works in MathJax.

    – egreg
    2 days ago











  • @PhelypeOleinik Excellent, it works - thanks. Feel free to post your response as an answer if you'd like the answer credit.

    – OverLordGoldDragon
    2 days ago











  • @egreg out of the box with no extra configuration?

    – daleif
    2 days ago














  • 5





    Welcome to TeX.SE! The command name has to be preceded by a backslash: newcommand{hs}[1]{hspace{#1}}. Add a backslash and it will work. The and third versions add braces that shouldn't be there, so they won't work. The fourth version won't work because numbers can't be in command names, and the first optional argument to newcommand can't be empty.

    – Phelype Oleinik
    2 days ago













  • Note that mathjax is not LaTeX so you should probably not expect any newcommand to work.

    – daleif
    2 days ago






  • 2





    @daleif newcommand works in MathJax.

    – egreg
    2 days ago











  • @PhelypeOleinik Excellent, it works - thanks. Feel free to post your response as an answer if you'd like the answer credit.

    – OverLordGoldDragon
    2 days ago











  • @egreg out of the box with no extra configuration?

    – daleif
    2 days ago








5




5





Welcome to TeX.SE! The command name has to be preceded by a backslash: newcommand{hs}[1]{hspace{#1}}. Add a backslash and it will work. The and third versions add braces that shouldn't be there, so they won't work. The fourth version won't work because numbers can't be in command names, and the first optional argument to newcommand can't be empty.

– Phelype Oleinik
2 days ago







Welcome to TeX.SE! The command name has to be preceded by a backslash: newcommand{hs}[1]{hspace{#1}}. Add a backslash and it will work. The and third versions add braces that shouldn't be there, so they won't work. The fourth version won't work because numbers can't be in command names, and the first optional argument to newcommand can't be empty.

– Phelype Oleinik
2 days ago















Note that mathjax is not LaTeX so you should probably not expect any newcommand to work.

– daleif
2 days ago





Note that mathjax is not LaTeX so you should probably not expect any newcommand to work.

– daleif
2 days ago




2




2





@daleif newcommand works in MathJax.

– egreg
2 days ago





@daleif newcommand works in MathJax.

– egreg
2 days ago













@PhelypeOleinik Excellent, it works - thanks. Feel free to post your response as an answer if you'd like the answer credit.

– OverLordGoldDragon
2 days ago





@PhelypeOleinik Excellent, it works - thanks. Feel free to post your response as an answer if you'd like the answer credit.

– OverLordGoldDragon
2 days ago













@egreg out of the box with no extra configuration?

– daleif
2 days ago





@egreg out of the box with no extra configuration?

– daleif
2 days ago










1 Answer
1






active

oldest

votes


















11














In usual conditions, all commands in TeX must be preceded by a backslash, to tell TeX that they are commands, so instead of



newcommand{hs}[1]{hspace{#1}}


you need



newcommand{hs}[1]{hspace{#1}}


which will work as you expect.



Side note: If you just want to create a copy of a command with another name, you can use let: leths=hspace. With the newcommand approach the hs command will use hspace, and with the let approach it will be a copy of hspace. One advantage of the latter is that hs*{argument} will work as you'd expect. With newcommand it won't.



The second version adds an extra pair of braces that shouldn't be there, so it won't work as well.



hspace{{1cm}} will expand to hskip{#1}relax, which isn't valid syntax and will throw you a Missing number error.



The third version is the same. The unit will only appear after the Missing number error, so it is of no use there. Besides, TeX doesn't know the unit px, so even if you remove the braces you'll still get a Illegal unit of measure.



The fourth contains, besides the illegal px unit, two problems. The first is that in usual circumstances numbers aren't allowed in command names, so you can't use hs1. The second is that the first optional argument of newcommand (the number of arguments) must not be empty (). An empty argument is very different from a missing argument! If you try to do that (after removing the number from the command name) you'll get another Missing number error because LaTeX was expecting a number there.






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
    });


    }
    });






    OverLordGoldDragon is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f471874%2ferror-creating-a-newcommand-which-uses-hspace%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









    11














    In usual conditions, all commands in TeX must be preceded by a backslash, to tell TeX that they are commands, so instead of



    newcommand{hs}[1]{hspace{#1}}


    you need



    newcommand{hs}[1]{hspace{#1}}


    which will work as you expect.



    Side note: If you just want to create a copy of a command with another name, you can use let: leths=hspace. With the newcommand approach the hs command will use hspace, and with the let approach it will be a copy of hspace. One advantage of the latter is that hs*{argument} will work as you'd expect. With newcommand it won't.



    The second version adds an extra pair of braces that shouldn't be there, so it won't work as well.



    hspace{{1cm}} will expand to hskip{#1}relax, which isn't valid syntax and will throw you a Missing number error.



    The third version is the same. The unit will only appear after the Missing number error, so it is of no use there. Besides, TeX doesn't know the unit px, so even if you remove the braces you'll still get a Illegal unit of measure.



    The fourth contains, besides the illegal px unit, two problems. The first is that in usual circumstances numbers aren't allowed in command names, so you can't use hs1. The second is that the first optional argument of newcommand (the number of arguments) must not be empty (). An empty argument is very different from a missing argument! If you try to do that (after removing the number from the command name) you'll get another Missing number error because LaTeX was expecting a number there.






    share|improve this answer




























      11














      In usual conditions, all commands in TeX must be preceded by a backslash, to tell TeX that they are commands, so instead of



      newcommand{hs}[1]{hspace{#1}}


      you need



      newcommand{hs}[1]{hspace{#1}}


      which will work as you expect.



      Side note: If you just want to create a copy of a command with another name, you can use let: leths=hspace. With the newcommand approach the hs command will use hspace, and with the let approach it will be a copy of hspace. One advantage of the latter is that hs*{argument} will work as you'd expect. With newcommand it won't.



      The second version adds an extra pair of braces that shouldn't be there, so it won't work as well.



      hspace{{1cm}} will expand to hskip{#1}relax, which isn't valid syntax and will throw you a Missing number error.



      The third version is the same. The unit will only appear after the Missing number error, so it is of no use there. Besides, TeX doesn't know the unit px, so even if you remove the braces you'll still get a Illegal unit of measure.



      The fourth contains, besides the illegal px unit, two problems. The first is that in usual circumstances numbers aren't allowed in command names, so you can't use hs1. The second is that the first optional argument of newcommand (the number of arguments) must not be empty (). An empty argument is very different from a missing argument! If you try to do that (after removing the number from the command name) you'll get another Missing number error because LaTeX was expecting a number there.






      share|improve this answer


























        11












        11








        11







        In usual conditions, all commands in TeX must be preceded by a backslash, to tell TeX that they are commands, so instead of



        newcommand{hs}[1]{hspace{#1}}


        you need



        newcommand{hs}[1]{hspace{#1}}


        which will work as you expect.



        Side note: If you just want to create a copy of a command with another name, you can use let: leths=hspace. With the newcommand approach the hs command will use hspace, and with the let approach it will be a copy of hspace. One advantage of the latter is that hs*{argument} will work as you'd expect. With newcommand it won't.



        The second version adds an extra pair of braces that shouldn't be there, so it won't work as well.



        hspace{{1cm}} will expand to hskip{#1}relax, which isn't valid syntax and will throw you a Missing number error.



        The third version is the same. The unit will only appear after the Missing number error, so it is of no use there. Besides, TeX doesn't know the unit px, so even if you remove the braces you'll still get a Illegal unit of measure.



        The fourth contains, besides the illegal px unit, two problems. The first is that in usual circumstances numbers aren't allowed in command names, so you can't use hs1. The second is that the first optional argument of newcommand (the number of arguments) must not be empty (). An empty argument is very different from a missing argument! If you try to do that (after removing the number from the command name) you'll get another Missing number error because LaTeX was expecting a number there.






        share|improve this answer













        In usual conditions, all commands in TeX must be preceded by a backslash, to tell TeX that they are commands, so instead of



        newcommand{hs}[1]{hspace{#1}}


        you need



        newcommand{hs}[1]{hspace{#1}}


        which will work as you expect.



        Side note: If you just want to create a copy of a command with another name, you can use let: leths=hspace. With the newcommand approach the hs command will use hspace, and with the let approach it will be a copy of hspace. One advantage of the latter is that hs*{argument} will work as you'd expect. With newcommand it won't.



        The second version adds an extra pair of braces that shouldn't be there, so it won't work as well.



        hspace{{1cm}} will expand to hskip{#1}relax, which isn't valid syntax and will throw you a Missing number error.



        The third version is the same. The unit will only appear after the Missing number error, so it is of no use there. Besides, TeX doesn't know the unit px, so even if you remove the braces you'll still get a Illegal unit of measure.



        The fourth contains, besides the illegal px unit, two problems. The first is that in usual circumstances numbers aren't allowed in command names, so you can't use hs1. The second is that the first optional argument of newcommand (the number of arguments) must not be empty (). An empty argument is very different from a missing argument! If you try to do that (after removing the number from the command name) you'll get another Missing number error because LaTeX was expecting a number there.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Phelype OleinikPhelype Oleinik

        22k54482




        22k54482






















            OverLordGoldDragon is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            OverLordGoldDragon is a new contributor. Be nice, and check out our Code of Conduct.













            OverLordGoldDragon is a new contributor. Be nice, and check out our Code of Conduct.












            OverLordGoldDragon is a new contributor. Be nice, and check out our Code of Conduct.
















            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%2f471874%2ferror-creating-a-newcommand-which-uses-hspace%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy