Math & ScienceUnderbrackets on tensor indices

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Underbrackets on tensor indices

Post by Cham »

I'm trying to add some underbrackets under tensor indices, but the indices size is changed. Here's a minimal working example of what I'm trying to do :

Code: Select all

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{tensor}
\usepackage[dvipsnames,table]{xcolor}
\newcommand*{\undercom}[3][gray]{\color{#1}\underbracket[0.5pt][4pt]{\normalcolor#2}_{#3}\normalcolor}

\begin{document}
A test :
	\begin{equation}
		\frac{1}{2} (\, \tensor{T}{_{\undercom{\lambda \nu}{} \mu}} + \tensor{T}{_{\mu \nu \lambda}} - \tensor{T}{_{\mu \lambda \nu}} ),
	\end{equation}
\end{document}
Preview :
index_underbracket.jpg
index_underbracket.jpg (6.28 KiB) Viewed 9684 times
How can I add brackets under the indices, without changing the size and position of the indices ? Ideally, the brackets should be in medium gray, or else the equation looks pretty "heavy".

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underbrackets on tensor indices

Post by localghost »

The index in your new command does not inherit the correct font size. Hence this has to be checked and the correct math font size has to be activated. Some macros from the LaTeX kernel do this job.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{tensor}
\usepackage[dvipsnames,table]{xcolor}

\makeatletter
\newcommand*{\undercom}[3][gray]{%
  \check@mathfonts
  \fontsize\sf@size\z@
  \math@fontstrue\selectfont%
  \color{#1}%
  \underbracket[0.5pt][4pt]{\normalcolor #2}_{#3}%
  \normalcolor%
}
\makeatother

\begin{document}
  A test:
  \begin{equation}
    \frac{1}{2} (\, \tensor{T}{_{\undercom{\lambda\nu}{}\mu}}+\tensor{T}{_{\mu\nu\lambda}}-\tensor{T}{_{\mu\lambda\nu}} )
  \end{equation}
\end{document}
The output is attached. By the way, very good minimal example.
Attachments
tesnsor-index-bracket.png
tesnsor-index-bracket.png (6.58 KiB) Viewed 9670 times
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Underbrackets on tensor indices

Post by Cham »

localghost,

the horizontal spacing isn't right for the last index (mu). The indices spacing should stay exactly the same as without the underbracket.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underbrackets on tensor indices

Post by localghost »

Then simply add a negative space (\!) to the definition of \undercom.

Code: Select all

\makeatletter
\newcommand*{\undercom}[3][gray]{%
  \check@mathfonts
  \fontsize\sf@size\z@
  \math@fontstrue\selectfont%
  \color{#1}%
  \underbracket[0.5pt][4pt]{\normalcolor #2}_{#3}%
  \normalcolor\!%
}
\makeatother
For more fine-tuning you can use \mkern with a (negative) length in multiples of mu, e.g. \mkern-3mu. Interference of the bracket and characters with descender cannot be ruled out.
Attachments
tesnsor-index-bracket-corrected.png
tesnsor-index-bracket-corrected.png (6.8 KiB) Viewed 9653 times
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Underbrackets on tensor indices

Post by Cham »

Thanks for the reply.

Hmm, is there a better way to emphasize some tensor indices ?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underbrackets on tensor indices

Post by localghost »

Cham wrote:[…] Hmm, is there a better way to emphasize some tensor indices ?
Does "emphasize" in this context mean something in the sense of highlighting or stressing certain indices? The bracket looked to me more like you wanted to tag them. Do you have some special ideas for emphasis (colored box, certain text color)?
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Underbrackets on tensor indices

Post by Cham »

localghost wrote: Does "emphasize" in this context mean something in the sense of highlighting or stressing certain indices? The bracket looked to me more like you wanted to tag them. Do you have some special ideas for emphasis (colored box, certain text color)?
A way to stressing certain indices, yes.

I mean a way to highlight some indices, without printing them in colors. I was thinking about a symbol under the indices (thus the underbracket idea). I don't know what is best for index emphasize.

This query is actually not very important to me, and I'm already ready to give up the idea. The underbracket idea was just an experiment.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underbrackets on tensor indices

Post by localghost »

Cham wrote:[…] I don't know what is best for index emphasize. […]
Nor me. I never faced a situation where I had to emphasize subscript indices.
Cham wrote:[…] This query is actually not very important to me, and I'm already ready to give up the idea. The underbracket idea was just an experiment.
Does this mean that my efforts have been for nothing? Seems as if I should think twice before answering next time and thus participating in experiments. m(
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Underbrackets on tensor indices

Post by Cham »

localghost wrote: Does this mean that my efforts have been for nothing? Seems as if I should think twice before answering next time and thus participating in experiments. m(
Sorry for the misunderstanding. That experiment could indeed be useful. In my book, I wanted to add an emphasize to some tensor indices, directly into the equations themselves, without knowing if it was really usefull or not.

While writing, it was obvious that the emphasize could be done in the text alone. However, I was wondering about the possibility to do the emphasize directly into the equations instead. I'm sure others may find this interesting too.

While I'm still not sure I'll add the index emphasize into the equations, I think it's a good idea to explore the idea a bit more.
Post Reply