Absolute Value Symbols












211















What is the "best LaTeX practices" for writing absolute value symbols? Are there any packages which provide good methods?



Some options include |x| and mid x mid, but I'm not sure which is best...










share|improve this question




















  • 37





    usepackage{amsmath}...(lvert xrvert); mid denotes a relation symbol and is wrong for the absolute value.

    – egreg
    Jan 31 '12 at 23:45






  • 1





    Should I do $usepackage{mathtools}...DeclarePairedDelimiter{vert}{lvert}{rvert} as per your answer to a previous question? tex.stackexchange.com/a/42274/9757

    – jamaicanworm
    Jan 31 '12 at 23:47








  • 3





    It's a good possibility. It depends on how many absolute values you have in your document; for a couple I wouldn't bother. But vert is not a good choice, as it's already defined.

    – egreg
    Jan 31 '12 at 23:50






  • 1





    Thanks! Why do people not just use the keyboard | symbol?

    – jamaicanworm
    Feb 1 '12 at 0:16






  • 20





    You can actually use |, but in some situations a certain care is needed. For instance (|{-1}|=1) without the braces would come out wrong, while (lvert-1rvert=1) surely gives correct output.

    – egreg
    Feb 1 '12 at 0:22
















211















What is the "best LaTeX practices" for writing absolute value symbols? Are there any packages which provide good methods?



Some options include |x| and mid x mid, but I'm not sure which is best...










share|improve this question




















  • 37





    usepackage{amsmath}...(lvert xrvert); mid denotes a relation symbol and is wrong for the absolute value.

    – egreg
    Jan 31 '12 at 23:45






  • 1





    Should I do $usepackage{mathtools}...DeclarePairedDelimiter{vert}{lvert}{rvert} as per your answer to a previous question? tex.stackexchange.com/a/42274/9757

    – jamaicanworm
    Jan 31 '12 at 23:47








  • 3





    It's a good possibility. It depends on how many absolute values you have in your document; for a couple I wouldn't bother. But vert is not a good choice, as it's already defined.

    – egreg
    Jan 31 '12 at 23:50






  • 1





    Thanks! Why do people not just use the keyboard | symbol?

    – jamaicanworm
    Feb 1 '12 at 0:16






  • 20





    You can actually use |, but in some situations a certain care is needed. For instance (|{-1}|=1) without the braces would come out wrong, while (lvert-1rvert=1) surely gives correct output.

    – egreg
    Feb 1 '12 at 0:22














211












211








211


85






What is the "best LaTeX practices" for writing absolute value symbols? Are there any packages which provide good methods?



Some options include |x| and mid x mid, but I'm not sure which is best...










share|improve this question
















What is the "best LaTeX practices" for writing absolute value symbols? Are there any packages which provide good methods?



Some options include |x| and mid x mid, but I'm not sure which is best...







math-mode symbols






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 1 '12 at 19:21









doncherry

35.3k23137209




35.3k23137209










asked Jan 31 '12 at 23:41









jamaicanwormjamaicanworm

10.7k3585128




10.7k3585128








  • 37





    usepackage{amsmath}...(lvert xrvert); mid denotes a relation symbol and is wrong for the absolute value.

    – egreg
    Jan 31 '12 at 23:45






  • 1





    Should I do $usepackage{mathtools}...DeclarePairedDelimiter{vert}{lvert}{rvert} as per your answer to a previous question? tex.stackexchange.com/a/42274/9757

    – jamaicanworm
    Jan 31 '12 at 23:47








  • 3





    It's a good possibility. It depends on how many absolute values you have in your document; for a couple I wouldn't bother. But vert is not a good choice, as it's already defined.

    – egreg
    Jan 31 '12 at 23:50






  • 1





    Thanks! Why do people not just use the keyboard | symbol?

    – jamaicanworm
    Feb 1 '12 at 0:16






  • 20





    You can actually use |, but in some situations a certain care is needed. For instance (|{-1}|=1) without the braces would come out wrong, while (lvert-1rvert=1) surely gives correct output.

    – egreg
    Feb 1 '12 at 0:22














  • 37





    usepackage{amsmath}...(lvert xrvert); mid denotes a relation symbol and is wrong for the absolute value.

    – egreg
    Jan 31 '12 at 23:45






  • 1





    Should I do $usepackage{mathtools}...DeclarePairedDelimiter{vert}{lvert}{rvert} as per your answer to a previous question? tex.stackexchange.com/a/42274/9757

    – jamaicanworm
    Jan 31 '12 at 23:47








  • 3





    It's a good possibility. It depends on how many absolute values you have in your document; for a couple I wouldn't bother. But vert is not a good choice, as it's already defined.

    – egreg
    Jan 31 '12 at 23:50






  • 1





    Thanks! Why do people not just use the keyboard | symbol?

    – jamaicanworm
    Feb 1 '12 at 0:16






  • 20





    You can actually use |, but in some situations a certain care is needed. For instance (|{-1}|=1) without the braces would come out wrong, while (lvert-1rvert=1) surely gives correct output.

    – egreg
    Feb 1 '12 at 0:22








37




37





usepackage{amsmath}...(lvert xrvert); mid denotes a relation symbol and is wrong for the absolute value.

– egreg
Jan 31 '12 at 23:45





usepackage{amsmath}...(lvert xrvert); mid denotes a relation symbol and is wrong for the absolute value.

– egreg
Jan 31 '12 at 23:45




1




1





Should I do $usepackage{mathtools}...DeclarePairedDelimiter{vert}{lvert}{rvert} as per your answer to a previous question? tex.stackexchange.com/a/42274/9757

– jamaicanworm
Jan 31 '12 at 23:47







Should I do $usepackage{mathtools}...DeclarePairedDelimiter{vert}{lvert}{rvert} as per your answer to a previous question? tex.stackexchange.com/a/42274/9757

– jamaicanworm
Jan 31 '12 at 23:47






3




3





It's a good possibility. It depends on how many absolute values you have in your document; for a couple I wouldn't bother. But vert is not a good choice, as it's already defined.

– egreg
Jan 31 '12 at 23:50





It's a good possibility. It depends on how many absolute values you have in your document; for a couple I wouldn't bother. But vert is not a good choice, as it's already defined.

– egreg
Jan 31 '12 at 23:50




1




1





Thanks! Why do people not just use the keyboard | symbol?

– jamaicanworm
Feb 1 '12 at 0:16





Thanks! Why do people not just use the keyboard | symbol?

– jamaicanworm
Feb 1 '12 at 0:16




20




20





You can actually use |, but in some situations a certain care is needed. For instance (|{-1}|=1) without the braces would come out wrong, while (lvert-1rvert=1) surely gives correct output.

– egreg
Feb 1 '12 at 0:22





You can actually use |, but in some situations a certain care is needed. For instance (|{-1}|=1) without the braces would come out wrong, while (lvert-1rvert=1) surely gives correct output.

– egreg
Feb 1 '12 at 0:22










7 Answers
7






active

oldest

votes


















168














I have been using the code below using DeclarePairedDelimiter from the mathtools package.



Since I don't think I have a case where I don't want this to scale based on the parameter, I make use of Swap definition of starred and non-starred command so that the normal use will automatically scale, and the starred version won't:



enter image description here



If you want it the other way around comment out the code between makeatother...makeatletter.



documentclass{article}
usepackage{mathtools}

DeclarePairedDelimiterabs{lvert}{rvert}%
DeclarePairedDelimiternorm{lVert}{rVert}%

% Swap the definition of abs* and norm*, so that abs
% and norm resizes the size of the brackets, and the
% starred version does not.
makeatletter
letoldabsabs
defabs{@ifstar{oldabs}{oldabs*}}
%
letoldnormnorm
defnorm{@ifstar{oldnorm}{oldnorm*}}
makeatother

newcommand*{Value}{frac{1}{2}x^2}%
begin{document}
[abs{Value} quad norm{Value} qquadtext{non-starred} ]
[abs*{Value} quad norm*{Value} qquadtext{starred}qquad]
end{document}





share|improve this answer





















  • 3





    @egreg: Agreed. But I have not encountered that with abs yet. BTW, I like your "always is generally wrong" :-)

    – Peter Grill
    Jan 31 '12 at 23:57








  • 2





    @jamaicanworm: I used dfrac in this case to make a larger fraction in inline mode. This is not normally recommended in inline mode as it breaks paragraph spacing. I will update the solution to remove that.

    – Peter Grill
    Feb 1 '12 at 0:16








  • 2





    There's a reason why it's preferable to use the *-version for the automatic resizing macro: always using left and right is wrong, in general.

    – egreg
    Oct 15 '12 at 17:24








  • 2





    +1, even though I have to say that this answer is not very skim-reading friendly with the huge "starred"/"non-starred" picture and the remark somewhere in the text "BTW, normal behaviour is the other way around". The question OTOH is one that makes everything in this thread very prone to being skim-read.

    – Christian
    Feb 27 '13 at 18:10






  • 3





    a definite advantage of using commands like abs and norm which no one seems to have mentioned: since the | symbol has special meaning in the makeidx context, trying to enter terminology using a bare | within index{...} will result in (delayed) errors and a lot of hair pulling for someone not really familiar with that usage. commands like the ones shown here (or even just bare vert, Vert or mid) is a lot safer and worth becoming familiar with.

    – barbara beeton
    Aug 19 '17 at 3:14



















74














Note if you just use | you get mathord spacing, which is different from the spacing you'd get from paired mathopen/mathclose delimiters or from left/right even if left/right doesn't stretch the symbol. Personally I prefer the left/right spacing from mathinner here (even if @egreg says I'm generally wrong:-)



documentclass{amsart}

begin{document}

$ log|x||y|b $

$ logleft|xright|left|yright|b $

$ logmathopen|xmathclose|mathopen|ymathclose|b $

end{document}


enter image description here






share|improve this answer

































    63














    One can also use commath package.



    documentclass{article}

    usepackage{commath}

    begin{document}
    [ norm{a vec{u}} = abs{a} , norm{vec{v}} ]
    end{document}


    enter image description here






    share|improve this answer





















    • 5





      +1 for this one, as it includes the semantics and has a relatively short syntax.

      – Martin Thoma
      May 28 '15 at 19:28






    • 1





      The spacing is somehow bad when used as subscript. The abs{} of physics is the better choice in my opinion.

      – fyaa
      Nov 21 '16 at 9:43



















    31














    The physics LaTeX package also implements abs and norm:



    documentclass{article}

    usepackage{physics}

    begin{document}
    [ c = abs{-c} ]
    [ vu{a} = frac{vb{a}}{norm{vb{a}}} ]
    end{document}


    enter image description here






    share|improve this answer





















    • 1





      I think this is the easiest solution!

      – Francesco Boccardo
      Feb 27 '18 at 11:23



















    9














    A simple, LaTeX native way of doing this is by using the | delimiter, with the standard left and right modifiers (source).



    For example:



    left| sum_{i=1}^{n} x^2 right|


    gives



    enter image description here






    share|improve this answer
























    • Also: using the | delimiter (without the preceding backslash) inserts a single vertical bar.

      – pietrodn
      Aug 11 '17 at 12:06






    • 1





      For fun try |+a|, as you can see this is wrong, and thus generally users should not just use |...| or |...| as they may accidentally come into situations where this is wrong. I'll leave it as an exercise why this happens. Plus in your example the fences does not need to be that tall.

      – daleif
      Aug 11 '17 at 12:11











    • With |+a| the spacing appears to be wrong, but with left|+aright| it appears to be fine.

      – pietrodn
      Aug 11 '17 at 12:19






    • 2





      Correct because one is left and the other is right. But left and right should only be added when actually needed (which is actually not often). My complain to your answer is that it is not good in general, for reasons that are explained in comments to other answers in this thread.

      – daleif
      Aug 11 '17 at 12:22





















    3














    For LyX users: maybe I have just overlooked how to do it correctly, but I couldn't find a way of doing this natively.



    I thus used a 1x1-Matrix environment and set the kind to determinant. It might just be a hack, but it works fine in my usecase.






    share|improve this answer































      1














      documentclass{article}
      usepackage{amsmath}
      begin{document}
      [
      %begin equation
      lVert w rVert
      %end equation
      ]
      end{document}


      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',
        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%2f43008%2fabsolute-value-symbols%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        7 Answers
        7






        active

        oldest

        votes








        7 Answers
        7






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        168














        I have been using the code below using DeclarePairedDelimiter from the mathtools package.



        Since I don't think I have a case where I don't want this to scale based on the parameter, I make use of Swap definition of starred and non-starred command so that the normal use will automatically scale, and the starred version won't:



        enter image description here



        If you want it the other way around comment out the code between makeatother...makeatletter.



        documentclass{article}
        usepackage{mathtools}

        DeclarePairedDelimiterabs{lvert}{rvert}%
        DeclarePairedDelimiternorm{lVert}{rVert}%

        % Swap the definition of abs* and norm*, so that abs
        % and norm resizes the size of the brackets, and the
        % starred version does not.
        makeatletter
        letoldabsabs
        defabs{@ifstar{oldabs}{oldabs*}}
        %
        letoldnormnorm
        defnorm{@ifstar{oldnorm}{oldnorm*}}
        makeatother

        newcommand*{Value}{frac{1}{2}x^2}%
        begin{document}
        [abs{Value} quad norm{Value} qquadtext{non-starred} ]
        [abs*{Value} quad norm*{Value} qquadtext{starred}qquad]
        end{document}





        share|improve this answer





















        • 3





          @egreg: Agreed. But I have not encountered that with abs yet. BTW, I like your "always is generally wrong" :-)

          – Peter Grill
          Jan 31 '12 at 23:57








        • 2





          @jamaicanworm: I used dfrac in this case to make a larger fraction in inline mode. This is not normally recommended in inline mode as it breaks paragraph spacing. I will update the solution to remove that.

          – Peter Grill
          Feb 1 '12 at 0:16








        • 2





          There's a reason why it's preferable to use the *-version for the automatic resizing macro: always using left and right is wrong, in general.

          – egreg
          Oct 15 '12 at 17:24








        • 2





          +1, even though I have to say that this answer is not very skim-reading friendly with the huge "starred"/"non-starred" picture and the remark somewhere in the text "BTW, normal behaviour is the other way around". The question OTOH is one that makes everything in this thread very prone to being skim-read.

          – Christian
          Feb 27 '13 at 18:10






        • 3





          a definite advantage of using commands like abs and norm which no one seems to have mentioned: since the | symbol has special meaning in the makeidx context, trying to enter terminology using a bare | within index{...} will result in (delayed) errors and a lot of hair pulling for someone not really familiar with that usage. commands like the ones shown here (or even just bare vert, Vert or mid) is a lot safer and worth becoming familiar with.

          – barbara beeton
          Aug 19 '17 at 3:14
















        168














        I have been using the code below using DeclarePairedDelimiter from the mathtools package.



        Since I don't think I have a case where I don't want this to scale based on the parameter, I make use of Swap definition of starred and non-starred command so that the normal use will automatically scale, and the starred version won't:



        enter image description here



        If you want it the other way around comment out the code between makeatother...makeatletter.



        documentclass{article}
        usepackage{mathtools}

        DeclarePairedDelimiterabs{lvert}{rvert}%
        DeclarePairedDelimiternorm{lVert}{rVert}%

        % Swap the definition of abs* and norm*, so that abs
        % and norm resizes the size of the brackets, and the
        % starred version does not.
        makeatletter
        letoldabsabs
        defabs{@ifstar{oldabs}{oldabs*}}
        %
        letoldnormnorm
        defnorm{@ifstar{oldnorm}{oldnorm*}}
        makeatother

        newcommand*{Value}{frac{1}{2}x^2}%
        begin{document}
        [abs{Value} quad norm{Value} qquadtext{non-starred} ]
        [abs*{Value} quad norm*{Value} qquadtext{starred}qquad]
        end{document}





        share|improve this answer





















        • 3





          @egreg: Agreed. But I have not encountered that with abs yet. BTW, I like your "always is generally wrong" :-)

          – Peter Grill
          Jan 31 '12 at 23:57








        • 2





          @jamaicanworm: I used dfrac in this case to make a larger fraction in inline mode. This is not normally recommended in inline mode as it breaks paragraph spacing. I will update the solution to remove that.

          – Peter Grill
          Feb 1 '12 at 0:16








        • 2





          There's a reason why it's preferable to use the *-version for the automatic resizing macro: always using left and right is wrong, in general.

          – egreg
          Oct 15 '12 at 17:24








        • 2





          +1, even though I have to say that this answer is not very skim-reading friendly with the huge "starred"/"non-starred" picture and the remark somewhere in the text "BTW, normal behaviour is the other way around". The question OTOH is one that makes everything in this thread very prone to being skim-read.

          – Christian
          Feb 27 '13 at 18:10






        • 3





          a definite advantage of using commands like abs and norm which no one seems to have mentioned: since the | symbol has special meaning in the makeidx context, trying to enter terminology using a bare | within index{...} will result in (delayed) errors and a lot of hair pulling for someone not really familiar with that usage. commands like the ones shown here (or even just bare vert, Vert or mid) is a lot safer and worth becoming familiar with.

          – barbara beeton
          Aug 19 '17 at 3:14














        168












        168








        168







        I have been using the code below using DeclarePairedDelimiter from the mathtools package.



        Since I don't think I have a case where I don't want this to scale based on the parameter, I make use of Swap definition of starred and non-starred command so that the normal use will automatically scale, and the starred version won't:



        enter image description here



        If you want it the other way around comment out the code between makeatother...makeatletter.



        documentclass{article}
        usepackage{mathtools}

        DeclarePairedDelimiterabs{lvert}{rvert}%
        DeclarePairedDelimiternorm{lVert}{rVert}%

        % Swap the definition of abs* and norm*, so that abs
        % and norm resizes the size of the brackets, and the
        % starred version does not.
        makeatletter
        letoldabsabs
        defabs{@ifstar{oldabs}{oldabs*}}
        %
        letoldnormnorm
        defnorm{@ifstar{oldnorm}{oldnorm*}}
        makeatother

        newcommand*{Value}{frac{1}{2}x^2}%
        begin{document}
        [abs{Value} quad norm{Value} qquadtext{non-starred} ]
        [abs*{Value} quad norm*{Value} qquadtext{starred}qquad]
        end{document}





        share|improve this answer















        I have been using the code below using DeclarePairedDelimiter from the mathtools package.



        Since I don't think I have a case where I don't want this to scale based on the parameter, I make use of Swap definition of starred and non-starred command so that the normal use will automatically scale, and the starred version won't:



        enter image description here



        If you want it the other way around comment out the code between makeatother...makeatletter.



        documentclass{article}
        usepackage{mathtools}

        DeclarePairedDelimiterabs{lvert}{rvert}%
        DeclarePairedDelimiternorm{lVert}{rVert}%

        % Swap the definition of abs* and norm*, so that abs
        % and norm resizes the size of the brackets, and the
        % starred version does not.
        makeatletter
        letoldabsabs
        defabs{@ifstar{oldabs}{oldabs*}}
        %
        letoldnormnorm
        defnorm{@ifstar{oldnorm}{oldnorm*}}
        makeatother

        newcommand*{Value}{frac{1}{2}x^2}%
        begin{document}
        [abs{Value} quad norm{Value} qquadtext{non-starred} ]
        [abs*{Value} quad norm*{Value} qquadtext{starred}qquad]
        end{document}






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 13 '17 at 12:35









        Community

        1




        1










        answered Jan 31 '12 at 23:48









        Peter GrillPeter Grill

        167k25445758




        167k25445758








        • 3





          @egreg: Agreed. But I have not encountered that with abs yet. BTW, I like your "always is generally wrong" :-)

          – Peter Grill
          Jan 31 '12 at 23:57








        • 2





          @jamaicanworm: I used dfrac in this case to make a larger fraction in inline mode. This is not normally recommended in inline mode as it breaks paragraph spacing. I will update the solution to remove that.

          – Peter Grill
          Feb 1 '12 at 0:16








        • 2





          There's a reason why it's preferable to use the *-version for the automatic resizing macro: always using left and right is wrong, in general.

          – egreg
          Oct 15 '12 at 17:24








        • 2





          +1, even though I have to say that this answer is not very skim-reading friendly with the huge "starred"/"non-starred" picture and the remark somewhere in the text "BTW, normal behaviour is the other way around". The question OTOH is one that makes everything in this thread very prone to being skim-read.

          – Christian
          Feb 27 '13 at 18:10






        • 3





          a definite advantage of using commands like abs and norm which no one seems to have mentioned: since the | symbol has special meaning in the makeidx context, trying to enter terminology using a bare | within index{...} will result in (delayed) errors and a lot of hair pulling for someone not really familiar with that usage. commands like the ones shown here (or even just bare vert, Vert or mid) is a lot safer and worth becoming familiar with.

          – barbara beeton
          Aug 19 '17 at 3:14














        • 3





          @egreg: Agreed. But I have not encountered that with abs yet. BTW, I like your "always is generally wrong" :-)

          – Peter Grill
          Jan 31 '12 at 23:57








        • 2





          @jamaicanworm: I used dfrac in this case to make a larger fraction in inline mode. This is not normally recommended in inline mode as it breaks paragraph spacing. I will update the solution to remove that.

          – Peter Grill
          Feb 1 '12 at 0:16








        • 2





          There's a reason why it's preferable to use the *-version for the automatic resizing macro: always using left and right is wrong, in general.

          – egreg
          Oct 15 '12 at 17:24








        • 2





          +1, even though I have to say that this answer is not very skim-reading friendly with the huge "starred"/"non-starred" picture and the remark somewhere in the text "BTW, normal behaviour is the other way around". The question OTOH is one that makes everything in this thread very prone to being skim-read.

          – Christian
          Feb 27 '13 at 18:10






        • 3





          a definite advantage of using commands like abs and norm which no one seems to have mentioned: since the | symbol has special meaning in the makeidx context, trying to enter terminology using a bare | within index{...} will result in (delayed) errors and a lot of hair pulling for someone not really familiar with that usage. commands like the ones shown here (or even just bare vert, Vert or mid) is a lot safer and worth becoming familiar with.

          – barbara beeton
          Aug 19 '17 at 3:14








        3




        3





        @egreg: Agreed. But I have not encountered that with abs yet. BTW, I like your "always is generally wrong" :-)

        – Peter Grill
        Jan 31 '12 at 23:57







        @egreg: Agreed. But I have not encountered that with abs yet. BTW, I like your "always is generally wrong" :-)

        – Peter Grill
        Jan 31 '12 at 23:57






        2




        2





        @jamaicanworm: I used dfrac in this case to make a larger fraction in inline mode. This is not normally recommended in inline mode as it breaks paragraph spacing. I will update the solution to remove that.

        – Peter Grill
        Feb 1 '12 at 0:16







        @jamaicanworm: I used dfrac in this case to make a larger fraction in inline mode. This is not normally recommended in inline mode as it breaks paragraph spacing. I will update the solution to remove that.

        – Peter Grill
        Feb 1 '12 at 0:16






        2




        2





        There's a reason why it's preferable to use the *-version for the automatic resizing macro: always using left and right is wrong, in general.

        – egreg
        Oct 15 '12 at 17:24







        There's a reason why it's preferable to use the *-version for the automatic resizing macro: always using left and right is wrong, in general.

        – egreg
        Oct 15 '12 at 17:24






        2




        2





        +1, even though I have to say that this answer is not very skim-reading friendly with the huge "starred"/"non-starred" picture and the remark somewhere in the text "BTW, normal behaviour is the other way around". The question OTOH is one that makes everything in this thread very prone to being skim-read.

        – Christian
        Feb 27 '13 at 18:10





        +1, even though I have to say that this answer is not very skim-reading friendly with the huge "starred"/"non-starred" picture and the remark somewhere in the text "BTW, normal behaviour is the other way around". The question OTOH is one that makes everything in this thread very prone to being skim-read.

        – Christian
        Feb 27 '13 at 18:10




        3




        3





        a definite advantage of using commands like abs and norm which no one seems to have mentioned: since the | symbol has special meaning in the makeidx context, trying to enter terminology using a bare | within index{...} will result in (delayed) errors and a lot of hair pulling for someone not really familiar with that usage. commands like the ones shown here (or even just bare vert, Vert or mid) is a lot safer and worth becoming familiar with.

        – barbara beeton
        Aug 19 '17 at 3:14





        a definite advantage of using commands like abs and norm which no one seems to have mentioned: since the | symbol has special meaning in the makeidx context, trying to enter terminology using a bare | within index{...} will result in (delayed) errors and a lot of hair pulling for someone not really familiar with that usage. commands like the ones shown here (or even just bare vert, Vert or mid) is a lot safer and worth becoming familiar with.

        – barbara beeton
        Aug 19 '17 at 3:14











        74














        Note if you just use | you get mathord spacing, which is different from the spacing you'd get from paired mathopen/mathclose delimiters or from left/right even if left/right doesn't stretch the symbol. Personally I prefer the left/right spacing from mathinner here (even if @egreg says I'm generally wrong:-)



        documentclass{amsart}

        begin{document}

        $ log|x||y|b $

        $ logleft|xright|left|yright|b $

        $ logmathopen|xmathclose|mathopen|ymathclose|b $

        end{document}


        enter image description here






        share|improve this answer






























          74














          Note if you just use | you get mathord spacing, which is different from the spacing you'd get from paired mathopen/mathclose delimiters or from left/right even if left/right doesn't stretch the symbol. Personally I prefer the left/right spacing from mathinner here (even if @egreg says I'm generally wrong:-)



          documentclass{amsart}

          begin{document}

          $ log|x||y|b $

          $ logleft|xright|left|yright|b $

          $ logmathopen|xmathclose|mathopen|ymathclose|b $

          end{document}


          enter image description here






          share|improve this answer




























            74












            74








            74







            Note if you just use | you get mathord spacing, which is different from the spacing you'd get from paired mathopen/mathclose delimiters or from left/right even if left/right doesn't stretch the symbol. Personally I prefer the left/right spacing from mathinner here (even if @egreg says I'm generally wrong:-)



            documentclass{amsart}

            begin{document}

            $ log|x||y|b $

            $ logleft|xright|left|yright|b $

            $ logmathopen|xmathclose|mathopen|ymathclose|b $

            end{document}


            enter image description here






            share|improve this answer















            Note if you just use | you get mathord spacing, which is different from the spacing you'd get from paired mathopen/mathclose delimiters or from left/right even if left/right doesn't stretch the symbol. Personally I prefer the left/right spacing from mathinner here (even if @egreg says I'm generally wrong:-)



            documentclass{amsart}

            begin{document}

            $ log|x||y|b $

            $ logleft|xright|left|yright|b $

            $ logmathopen|xmathclose|mathopen|ymathclose|b $

            end{document}


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 30 '15 at 20:44









            Svend Tveskæg

            20.8k1052142




            20.8k1052142










            answered Feb 1 '12 at 10:32









            David CarlisleDavid Carlisle

            496k4111441890




            496k4111441890























                63














                One can also use commath package.



                documentclass{article}

                usepackage{commath}

                begin{document}
                [ norm{a vec{u}} = abs{a} , norm{vec{v}} ]
                end{document}


                enter image description here






                share|improve this answer





















                • 5





                  +1 for this one, as it includes the semantics and has a relatively short syntax.

                  – Martin Thoma
                  May 28 '15 at 19:28






                • 1





                  The spacing is somehow bad when used as subscript. The abs{} of physics is the better choice in my opinion.

                  – fyaa
                  Nov 21 '16 at 9:43
















                63














                One can also use commath package.



                documentclass{article}

                usepackage{commath}

                begin{document}
                [ norm{a vec{u}} = abs{a} , norm{vec{v}} ]
                end{document}


                enter image description here






                share|improve this answer





















                • 5





                  +1 for this one, as it includes the semantics and has a relatively short syntax.

                  – Martin Thoma
                  May 28 '15 at 19:28






                • 1





                  The spacing is somehow bad when used as subscript. The abs{} of physics is the better choice in my opinion.

                  – fyaa
                  Nov 21 '16 at 9:43














                63












                63








                63







                One can also use commath package.



                documentclass{article}

                usepackage{commath}

                begin{document}
                [ norm{a vec{u}} = abs{a} , norm{vec{v}} ]
                end{document}


                enter image description here






                share|improve this answer















                One can also use commath package.



                documentclass{article}

                usepackage{commath}

                begin{document}
                [ norm{a vec{u}} = abs{a} , norm{vec{v}} ]
                end{document}


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 20 '14 at 14:35

























                answered Dec 8 '13 at 17:21









                WildcatWildcat

                79358




                79358








                • 5





                  +1 for this one, as it includes the semantics and has a relatively short syntax.

                  – Martin Thoma
                  May 28 '15 at 19:28






                • 1





                  The spacing is somehow bad when used as subscript. The abs{} of physics is the better choice in my opinion.

                  – fyaa
                  Nov 21 '16 at 9:43














                • 5





                  +1 for this one, as it includes the semantics and has a relatively short syntax.

                  – Martin Thoma
                  May 28 '15 at 19:28






                • 1





                  The spacing is somehow bad when used as subscript. The abs{} of physics is the better choice in my opinion.

                  – fyaa
                  Nov 21 '16 at 9:43








                5




                5





                +1 for this one, as it includes the semantics and has a relatively short syntax.

                – Martin Thoma
                May 28 '15 at 19:28





                +1 for this one, as it includes the semantics and has a relatively short syntax.

                – Martin Thoma
                May 28 '15 at 19:28




                1




                1





                The spacing is somehow bad when used as subscript. The abs{} of physics is the better choice in my opinion.

                – fyaa
                Nov 21 '16 at 9:43





                The spacing is somehow bad when used as subscript. The abs{} of physics is the better choice in my opinion.

                – fyaa
                Nov 21 '16 at 9:43











                31














                The physics LaTeX package also implements abs and norm:



                documentclass{article}

                usepackage{physics}

                begin{document}
                [ c = abs{-c} ]
                [ vu{a} = frac{vb{a}}{norm{vb{a}}} ]
                end{document}


                enter image description here






                share|improve this answer





















                • 1





                  I think this is the easiest solution!

                  – Francesco Boccardo
                  Feb 27 '18 at 11:23
















                31














                The physics LaTeX package also implements abs and norm:



                documentclass{article}

                usepackage{physics}

                begin{document}
                [ c = abs{-c} ]
                [ vu{a} = frac{vb{a}}{norm{vb{a}}} ]
                end{document}


                enter image description here






                share|improve this answer





















                • 1





                  I think this is the easiest solution!

                  – Francesco Boccardo
                  Feb 27 '18 at 11:23














                31












                31








                31







                The physics LaTeX package also implements abs and norm:



                documentclass{article}

                usepackage{physics}

                begin{document}
                [ c = abs{-c} ]
                [ vu{a} = frac{vb{a}}{norm{vb{a}}} ]
                end{document}


                enter image description here






                share|improve this answer















                The physics LaTeX package also implements abs and norm:



                documentclass{article}

                usepackage{physics}

                begin{document}
                [ c = abs{-c} ]
                [ vu{a} = frac{vb{a}}{norm{vb{a}}} ]
                end{document}


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jul 22 '16 at 17:49

























                answered Jul 22 '16 at 17:00









                NauticalMileNauticalMile

                45848




                45848








                • 1





                  I think this is the easiest solution!

                  – Francesco Boccardo
                  Feb 27 '18 at 11:23














                • 1





                  I think this is the easiest solution!

                  – Francesco Boccardo
                  Feb 27 '18 at 11:23








                1




                1





                I think this is the easiest solution!

                – Francesco Boccardo
                Feb 27 '18 at 11:23





                I think this is the easiest solution!

                – Francesco Boccardo
                Feb 27 '18 at 11:23











                9














                A simple, LaTeX native way of doing this is by using the | delimiter, with the standard left and right modifiers (source).



                For example:



                left| sum_{i=1}^{n} x^2 right|


                gives



                enter image description here






                share|improve this answer
























                • Also: using the | delimiter (without the preceding backslash) inserts a single vertical bar.

                  – pietrodn
                  Aug 11 '17 at 12:06






                • 1





                  For fun try |+a|, as you can see this is wrong, and thus generally users should not just use |...| or |...| as they may accidentally come into situations where this is wrong. I'll leave it as an exercise why this happens. Plus in your example the fences does not need to be that tall.

                  – daleif
                  Aug 11 '17 at 12:11











                • With |+a| the spacing appears to be wrong, but with left|+aright| it appears to be fine.

                  – pietrodn
                  Aug 11 '17 at 12:19






                • 2





                  Correct because one is left and the other is right. But left and right should only be added when actually needed (which is actually not often). My complain to your answer is that it is not good in general, for reasons that are explained in comments to other answers in this thread.

                  – daleif
                  Aug 11 '17 at 12:22


















                9














                A simple, LaTeX native way of doing this is by using the | delimiter, with the standard left and right modifiers (source).



                For example:



                left| sum_{i=1}^{n} x^2 right|


                gives



                enter image description here






                share|improve this answer
























                • Also: using the | delimiter (without the preceding backslash) inserts a single vertical bar.

                  – pietrodn
                  Aug 11 '17 at 12:06






                • 1





                  For fun try |+a|, as you can see this is wrong, and thus generally users should not just use |...| or |...| as they may accidentally come into situations where this is wrong. I'll leave it as an exercise why this happens. Plus in your example the fences does not need to be that tall.

                  – daleif
                  Aug 11 '17 at 12:11











                • With |+a| the spacing appears to be wrong, but with left|+aright| it appears to be fine.

                  – pietrodn
                  Aug 11 '17 at 12:19






                • 2





                  Correct because one is left and the other is right. But left and right should only be added when actually needed (which is actually not often). My complain to your answer is that it is not good in general, for reasons that are explained in comments to other answers in this thread.

                  – daleif
                  Aug 11 '17 at 12:22
















                9












                9








                9







                A simple, LaTeX native way of doing this is by using the | delimiter, with the standard left and right modifiers (source).



                For example:



                left| sum_{i=1}^{n} x^2 right|


                gives



                enter image description here






                share|improve this answer













                A simple, LaTeX native way of doing this is by using the | delimiter, with the standard left and right modifiers (source).



                For example:



                left| sum_{i=1}^{n} x^2 right|


                gives



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 11 '17 at 12:04









                pietrodnpietrodn

                26124




                26124













                • Also: using the | delimiter (without the preceding backslash) inserts a single vertical bar.

                  – pietrodn
                  Aug 11 '17 at 12:06






                • 1





                  For fun try |+a|, as you can see this is wrong, and thus generally users should not just use |...| or |...| as they may accidentally come into situations where this is wrong. I'll leave it as an exercise why this happens. Plus in your example the fences does not need to be that tall.

                  – daleif
                  Aug 11 '17 at 12:11











                • With |+a| the spacing appears to be wrong, but with left|+aright| it appears to be fine.

                  – pietrodn
                  Aug 11 '17 at 12:19






                • 2





                  Correct because one is left and the other is right. But left and right should only be added when actually needed (which is actually not often). My complain to your answer is that it is not good in general, for reasons that are explained in comments to other answers in this thread.

                  – daleif
                  Aug 11 '17 at 12:22





















                • Also: using the | delimiter (without the preceding backslash) inserts a single vertical bar.

                  – pietrodn
                  Aug 11 '17 at 12:06






                • 1





                  For fun try |+a|, as you can see this is wrong, and thus generally users should not just use |...| or |...| as they may accidentally come into situations where this is wrong. I'll leave it as an exercise why this happens. Plus in your example the fences does not need to be that tall.

                  – daleif
                  Aug 11 '17 at 12:11











                • With |+a| the spacing appears to be wrong, but with left|+aright| it appears to be fine.

                  – pietrodn
                  Aug 11 '17 at 12:19






                • 2





                  Correct because one is left and the other is right. But left and right should only be added when actually needed (which is actually not often). My complain to your answer is that it is not good in general, for reasons that are explained in comments to other answers in this thread.

                  – daleif
                  Aug 11 '17 at 12:22



















                Also: using the | delimiter (without the preceding backslash) inserts a single vertical bar.

                – pietrodn
                Aug 11 '17 at 12:06





                Also: using the | delimiter (without the preceding backslash) inserts a single vertical bar.

                – pietrodn
                Aug 11 '17 at 12:06




                1




                1





                For fun try |+a|, as you can see this is wrong, and thus generally users should not just use |...| or |...| as they may accidentally come into situations where this is wrong. I'll leave it as an exercise why this happens. Plus in your example the fences does not need to be that tall.

                – daleif
                Aug 11 '17 at 12:11





                For fun try |+a|, as you can see this is wrong, and thus generally users should not just use |...| or |...| as they may accidentally come into situations where this is wrong. I'll leave it as an exercise why this happens. Plus in your example the fences does not need to be that tall.

                – daleif
                Aug 11 '17 at 12:11













                With |+a| the spacing appears to be wrong, but with left|+aright| it appears to be fine.

                – pietrodn
                Aug 11 '17 at 12:19





                With |+a| the spacing appears to be wrong, but with left|+aright| it appears to be fine.

                – pietrodn
                Aug 11 '17 at 12:19




                2




                2





                Correct because one is left and the other is right. But left and right should only be added when actually needed (which is actually not often). My complain to your answer is that it is not good in general, for reasons that are explained in comments to other answers in this thread.

                – daleif
                Aug 11 '17 at 12:22







                Correct because one is left and the other is right. But left and right should only be added when actually needed (which is actually not often). My complain to your answer is that it is not good in general, for reasons that are explained in comments to other answers in this thread.

                – daleif
                Aug 11 '17 at 12:22













                3














                For LyX users: maybe I have just overlooked how to do it correctly, but I couldn't find a way of doing this natively.



                I thus used a 1x1-Matrix environment and set the kind to determinant. It might just be a hack, but it works fine in my usecase.






                share|improve this answer




























                  3














                  For LyX users: maybe I have just overlooked how to do it correctly, but I couldn't find a way of doing this natively.



                  I thus used a 1x1-Matrix environment and set the kind to determinant. It might just be a hack, but it works fine in my usecase.






                  share|improve this answer


























                    3












                    3








                    3







                    For LyX users: maybe I have just overlooked how to do it correctly, but I couldn't find a way of doing this natively.



                    I thus used a 1x1-Matrix environment and set the kind to determinant. It might just be a hack, but it works fine in my usecase.






                    share|improve this answer













                    For LyX users: maybe I have just overlooked how to do it correctly, but I couldn't find a way of doing this natively.



                    I thus used a 1x1-Matrix environment and set the kind to determinant. It might just be a hack, but it works fine in my usecase.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 28 '15 at 18:51









                    MeneMene

                    326210




                    326210























                        1














                        documentclass{article}
                        usepackage{amsmath}
                        begin{document}
                        [
                        %begin equation
                        lVert w rVert
                        %end equation
                        ]
                        end{document}


                        enter image description here






                        share|improve this answer




























                          1














                          documentclass{article}
                          usepackage{amsmath}
                          begin{document}
                          [
                          %begin equation
                          lVert w rVert
                          %end equation
                          ]
                          end{document}


                          enter image description here






                          share|improve this answer


























                            1












                            1








                            1







                            documentclass{article}
                            usepackage{amsmath}
                            begin{document}
                            [
                            %begin equation
                            lVert w rVert
                            %end equation
                            ]
                            end{document}


                            enter image description here






                            share|improve this answer













                            documentclass{article}
                            usepackage{amsmath}
                            begin{document}
                            [
                            %begin equation
                            lVert w rVert
                            %end equation
                            ]
                            end{document}


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 20 '18 at 9:21









                            alhelalalhelal

                            1,014219




                            1,014219






























                                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%2f43008%2fabsolute-value-symbols%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?