Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

i have this equation

\begin{equation} D{_{T__1}_,}{_{T__2}} (g)= | H{_T{__1}} (g)- H{_{T__2}} (g)|=|log_2 P{_{T__1}}(g)-log_2 P{_T{__2}} (g)| \end{equation}

and it shows some error and also the number of this equation is in wrong place

as shown in picture

any advice how to fix it?

this

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

Don't try to use __ (double-_) to indicate a double-subscripted position for the subsequent material. Instead, use { and } (curly braces) to indicate "grouping" at the first and second level of subscripts.

enter image description here

\documentclass{article}
\begin{document} 
\begin{equation} D_{{T_1},{T_2}} (g)= \lvert H_{T_1} (g)- H_{T_2} (g)\rvert
  =\lvert \log_2 P_{T_1}(g)-\log_2 P_{T_2} (g) \rvert 
\end{equation}
\end{document}

Two additional comments:

  • As you'll see from the code, I've replaced the occurrences of the string log with \log, i.e., prefixed a \ (backslash) character to indicate that the string "log" is an "operator" and should be (i) typeset in upright characters rather than in italics and (ii) surrounded by a little bit of extra space on both sides. Both aspects make it "stand out" a bit, visually speaking, and ensure that it's not misread as a sequence of variables named l, o, and g.

  • Using |...| to denote the taking of absolute values is poor LaTeX practice for several reasons. For one, these "fence" symbols won't grow automatically in vertical size with the material they enclose. More importantly, the spacing around the fence symbols won't necessarily be right. At a minimum (as is also done in the example code above), one should use \lvert ... \rvert to enclose the material. If there are more than just a couple of occurrences of the absolute value operations, it pays to create a dedicated macro (to be used in math mode, of course) such as

    \newcommand{\abs}[1]{\lvert #1 \rvert}
    

    and then type \abs{ H_{T_1} (g) - H_{T_2} (g) }. Doing so employs "logical" layouts of the code rather than visual layouts.

    Better still, load the mathtools package and issue the command

    \DeclarePairedDelimiter\abs{\lvert}{\rvert}
    

    in the preamble. With this setup, the command \abs*{ ... } (note the * character) will generate fences that grow automatically with the vertical height of the material being enclosed.

Happy TeXing!

share|improve this answer
    
Plus | isn't really the best symbols (in general) to use as a abs marker (wrong category) –  daleif Feb 3 at 7:43
    
It is not the size that is the problem. I'm trying to get people to stop using |...| for say abs value. They should be using \lvert ...\rvert` or similar. |...| is not correct in all situations. And of course it is better to let a macro add the vertical bars, makes the code more readable, especially then scaling is involved –  daleif Feb 3 at 8:52
1  
@daleif - OK, I'll provide an addendum to address the | matter. :-) –  Mico Feb 3 at 8:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.