In electrical engineering, when speaking of boolean algebra, it is common to represent negation (¬ P) with an overline and logical and (P ∧ Q) with juxtaposition. In LaTeX, I was using the \overline
command in math mode for negation.
That worked well until I noticed that the lines over adjacent symbols were being combined. In HTML, this is like ¬ (P ∧ Q) becoming ¬ P ∧ ¬ Q, which is completely different.
As an example, consider this LaTeX source:
\documentclass[varwidth]{standalone}
\begin{document}
$\overline P \overline Q$
$\overline{P Q}$
$\overline P \ \overline Q$
\end{document}
It produces the following output:
$\overline P \overline Q$
should look different from $\overline{P Q}$
; the former should have two separate overlines and the latter should have a single overline that extends across both P and Q.
I can get close to what I want with $\overline P \ \overline Q$
, but that has two problems. First, it introduces extra space between the P and the Q that wouldn't otherwise be there. Second, it requires manually and explicitly identifying how things should be placed on the page, which is difficult, error prone, and (as I understand) against the philosophy of TeX in that I'm supposed to worry about semantics while TeX handles the layout.
Note that I can't use \bar
, because I often do need a single overline to stretch across both symbols (or even over a more complex sentence).
I'm guessing that the answer to my question is that I'm abusing \overline
, and that I should instead be using some other math-mode command that is already defined in amsmath or even in LaTeX itself. In any case, I'm avoiding complex macros etc. because I very much doubt that they're the right choice here (or if they are, then there's already a package for it).
Lastly, I'll point out that very similar questions have been asked before, but I haven't found a satisfying answer to this one. In particular this question is pretty much identical to mine, but the answer there is not without problems. I've described that solution along with a couple others in my answer below.
$\average[2.5]{P}\average[2.5]{Q}$
?\average
macro prodived in @egreg's solution should work perfectly for you. I don't understand the basis for your claim that that solution "focuses on the subscripts". Indeed, it works equally well for expressions with and without subscripts.