Math & ScienceCrossed-out underbracket

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Saskatchewan
Posts: 3
Joined: Sun Jun 26, 2011 9:30 pm

Crossed-out underbracket

Post by Saskatchewan »

I use underbrackets to show that two elements can be reduced to, let's call it, an empty string. My problem is that in some examples I need to show that particular elements don't match - string can't be reduced by matching these two elements.

To make an underbracket, I simply write:

Code: Select all

\documentclass{article}
\usepackage{mathtools}

\begin{document}
    a\underbracket{b c d b}
\end{document}
Question is: how can I make a crossed-out underbracket? (Something like "\not \underbracket" which of course doesn't work.) I would like not to import additional packages, if possible.

Recommended reading 2024:

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

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

frederic
Posts: 9
Joined: Mon Jun 27, 2011 7:25 pm

Crossed-out underbracket

Post by frederic »

I know you asked for no other package, IF POSSIBLE. Unfortunately, I'm only able to solve your question using Tikz. There are certainly other ways; others can find them.

I defined two macros, one to underbrace and the other to "not-underbrace".

Code: Select all

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\underb}[1]{\tikz[baseline=(text.base)]{
	\node[inner sep=0pt,outer sep=0pt,text height = 2ex] (text) {#1};
	\draw[thick] (text.south east) -- ++(0,-0.1) -| (text.south west);}}

	
\newcommand{\notunderb}[1]{\tikz[baseline=(text.base)]{
	\node[inner sep=0pt,outer sep=0pt,text height = 2ex] (text) {#1};
	\coordinate (mid) at ($(text.south east)!0.5!(text.south west) - (0,0.1)$);
	\draw[thick] (text.south east) -- ++(0,-0.1) -| (text.south west);
	\draw[rotate=60,shift=(mid),thick] (-0.1,0) -- (0.1,0);
	}}

\begin{document}

kkjkk\underb{qweuytiuy}

\notunderb{qweuytiuy}

\end{document}
I hope this helps
User avatar
Saskatchewan
Posts: 3
Joined: Sun Jun 26, 2011 9:30 pm

Crossed-out underbracket

Post by Saskatchewan »

Thanks, it's almost it, but there is one problem. I should have mentioned it before, that I need to use those commands in math mode - some commands need to be nested. That is, although this works:

Code: Select all

\underb{$\pi^l \pi$}
I have to use it like that:

Code: Select all

$\underb{\pi^l \pi}$
I don't know Tikz at all, so I'm not able to solve it by myself.

There are also two, small issues, I could live with. Lets have an example:

Code: Select all

\notunderb{\bar{q}\underb{\pi^\ell \pi}\underb{j i^r}s_1}
1. There is no space between the two nested underbrackets
2. Second nested underbrackets is below the first one (because of "j" standing out below the baseline)
frederic
Posts: 9
Joined: Mon Jun 27, 2011 7:25 pm

Crossed-out underbracket

Post by frederic »

Here is a modified version. It works in math mode (actually, whatever is given as an argument is automatically in mathmode. I fixed the alignment problem. I also added code to allow for nesting, but I'm not proud of that bit because it is not elegant: you must enter a second argument, indicating the level for the underbrace (starts at 0, see the example). If someone can make it happen automatically, then great. You might want to try your question on http://tex.stackexchange.com/ .

The code is

Code: Select all

\documentclass{minimal}

\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\underb}[2]{\tikz[baseline=(text.base)]{
	\node[inner sep=0pt,outer sep=0pt,text height = 2ex] (text) {\ensuremath{#1}};
	\draw[thick] ($(text.base east)-(0,0.1)-#2*(0,2ex)$) -- ++(0,-0.1) -| ($(text.base west)-(0,0.1)-(0,{#2*1ex})$);}}

	
\newcommand{\notunderb}[2]{\tikz[baseline=(text.base)]{
	\node[inner sep=0pt,outer sep=0pt,text height = 2ex] (text) {\ensuremath{#1}};
	\coordinate (mid) at ($(text.base east)!0.5!(text.base west) - (0,0.2)-#2*(0,1ex)$);
	\draw[thick] ($(text.base east)-(0,0.1)-#2*(0,1ex)$) -- ++(0,-0.1) -| ($(text.base west)-(0,0.1)-#2*(0,1ex)$);
	\draw[rotate=60,shift=(mid),thick] (-0.1,0) -- (0.1,0);
	}}

\begin{document}

kkjkk\underb{qweuytiuy_1}{0}

\notunderb{qweuy_1tiuy}{0}

\underb{\pi^l \pi}{0}

\notunderb{\bar{q}\underb{\pi^\ell \pi}{0}\,\underb{j i^r}{0}s_1}{1}

\end{document}
User avatar
Saskatchewan
Posts: 3
Joined: Sun Jun 26, 2011 9:30 pm

Crossed-out underbracket

Post by Saskatchewan »

I fixed it, because it was breaking with more levels:

Code: Select all

\newcommand{\underb}[2]{\tikz[baseline=(text.base)]{
   \node[inner sep=0pt,outer sep=0pt,text height = 2ex] (text) {\ensuremath{#1}};
   \draw[thick] ($(text.base east)-(0,0.1)-#2*(0,1ex)$) -- ++(0,-0.1) -| ($(text.base west)-(0,0.1)-(0,{#2*1ex})$);}}

   
\newcommand{\notunderb}[2]{\tikz[baseline=(text.base)]{
   \node[inner sep=0pt,outer sep=0pt,text height = 2ex] (text) {\ensuremath{#1}};
   \coordinate (mid) at ($(text.base east)!0.5!(text.base west) - (0,0.2)-#2*(0,1ex)$);
   \draw[thick] ($(text.base east)-(0,0.1)-#2*(0,1ex)$) -- ++(0,-0.1) -| ($(text.base west)-(0,0.1)-#2*(0,1ex)$);
   \draw[rotate=60,shift=(mid),thick] (-0.1,0) -- (0.1,0);
   }}
It looks perfect with this code, but because of having to enter levels of nested underbrackets manually, I think I'll use a combination of the two codes.

I tried setting a custom counter, but after compiling the code I realized, underbrackets are parsed from last to first - it draws underbrackets "upside down". Here's the code, if somebody's interested:

Code: Select all

\documentclass{minimal}

\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{calc}

\newcounter{bracklev}
\setcounter{bracklev}{-1}

\newcommand{\underb}[1]{
   \addtocounter{bracklev}{+1}
   \tikz[baseline=(text.base)]{
      \node[inner sep=0pt,outer sep=0pt,text height = 2ex] (text) {\ensuremath{#1}};
      \draw[thick] ($(text.base east)-(0,0.1)-\value{bracklev}*(0,1ex)$) -- ++(0,-0.1) -| ($(text.base west)-(0,0.1)-(0,{\value{bracklev}*1ex})$);}
   \addtocounter{bracklev}{-1}
}

   
\newcommand{\notunderb}[1]{
   \addtocounter{bracklev}{+1}
   \tikz[baseline=(text.base)]{
      \node[inner sep=0pt,outer sep=0pt,text height = 2ex] (text) {\ensuremath{#1}};
      \coordinate (mid) at ($(text.base east)!0.5!(text.base west) - (0,0.2)-\value{bracklev}*(0,1ex)$);
      \draw[thick] ($(text.base east)-(0,0.1)-\value{bracklev}*(0,1ex)$) -- ++(0,-0.1) -| ($(text.base west)-(0,0.1)-\value{bracklev}*(0,1ex)$);
      \draw[rotate=60,shift=(mid),thick] (-0.1,0) -- (0.1,0);}
   \addtocounter{bracklev}{-1}
}

\begin{document}

\notunderb{a\notunderb{b\underb{c\underb{p\notunderb{\bar{q}\underb{\pi^\ell \pi}\underb{j i^r}s_1} s_2}d}e}f}

\end{document}
Anyway, thank you very much for your help.
Post Reply