Math & ScienceIntersecting arguments

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
vmarko
Posts: 4
Joined: Sat Oct 16, 2010 5:02 pm

Intersecting arguments

Post by vmarko »

Hi everyone!

This is my first post to this forum, so please don't mind if I don't know appropriate etiquette here. :-)

My question is simple: given a sequence of symbols in an equation, say "abcd", I want to underline "abc" part, while at the same time overline "bcd" part. The

Code: Select all

\underline{a\overline{bc}d}
obviously doesn't work, since the arguments of \overline and \underline should be intersected.

So how does one deal with intersecting arguments like this in LaTeX?

Thanks, :-)
Marko

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Intersecting arguments

Post by gmedina »

Hi, Marko and welcome to the board!

You could try something like this:

Code: Select all

\documentclass{article}

\begin{document}

$\overline{\mkern-10mu\underline{abc}d}$

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
vmarko
Posts: 4
Joined: Sat Oct 16, 2010 5:02 pm

Re: Intersecting arguments

Post by vmarko »

Umm, yes, that's it. If you could only explain to me how this works? I'd like to be able to create a generic definition for this type of stuff (using \newcommand for example), because I need to typeset this things a lot...

Thanks, :-)
Marko
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Intersecting arguments

Post by gmedina »

\mkern inserts a kern in mu units. Will your expressions always have the same form? I mean, will they always be formed by four characters, and should always the first three appear underlined and the last three overlined?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
vmarko
Posts: 4
Joined: Sat Oct 16, 2010 5:02 pm

Re: Intersecting arguments

Post by vmarko »

No, I need to overline and underline various sequences of symbols (numbers, letters, accented symbols, all sorts of stuff), in various combinations, several times, etc. This is in appearance very similar to Wick contraction symbols (see the first example equation in
http://www.fzu.cz/~kolorenc/tex/simplew ... lewick.pdf ). The code that generates those Wick contractions is way to complicated for me to understand and modify for \overline and \underline, so I am looking for some way to deal with this problem in the easiest way possible.

I need a generic solution to tell TeX that the argument of a command (say, \underline) starts here and ends there, but not using generic { and }, since they will get mixed and confused with arguments of other commands.

I've read about \mkern in the meantime, but I have a feeling it is more of a hack for the first case I gave you, and hardly extendible to more general cases.

Any thoughts?

Thanks, :-)
Marko
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Intersecting arguments

Post by gmedina »

The following modification to the code of simplewick.sty will do the job (if you are not using the simplewick package; if you are using this package, let me know and I will modify my code accordingly):

Code: Select all

\documentclass{article}

\makeatletter
% modification to the code of simplewick.sty
\newbox\swb@xone
\newbox\swb@xtwo
\newbox\swb@xthree
\newbox\swb@xfour
\newdimen\swdimen@ne
\newdimen\swdimentw@

\newcommand{\acontraction}[5][1ex]{%
\mathchoice
  {\acontraction@\displaystyle{#2}{#3}{#4}{#5}{#1}}%
  {\acontraction@\textstyle{#2}{#3}{#4}{#5}{#1}}%
  {\acontraction@\scriptstyle{#2}{#3}{#4}{#5}{#1}}%
  {\acontraction@\scriptscriptstyle{#2}{#3}{#4}{#5}{#1}}}%
\newcommand{\acontraction@}[6]{%
  \setbox\swb@xone=\hbox{${}#1{}#2{}$}%
  \setbox\swb@xtwo=\hbox{${}#1{}#3{}$}%
  \setbox\swb@xthree=\hbox{${}#1{}#4{}$}%
  \setbox\swb@xfour=\hbox{${}#1{}#5{}$}%
  \swdimen@ne=\wd\swb@xtwo%
  \advance\swdimen@ne by \wd\swb@xfour%
  \divide\swdimen@ne by 2%
  \advance\swdimen@ne by \wd\swb@xthree%
  \vbox{%
    \hbox to 0pt{%
      \kern \wd\swb@xone%
      \kern 0.5\wd\swb@xtwo%
       \acontraction@@{\swdimen@ne}{#6}%
       \hss%
       }%
    \vskip 0.5ex% how far above the line starts
    \vskip\ht\swb@xtwo
  }
}
\newcommand{\acontracted}[5][1ex]{%
  \acontraction[#1]{#2}{#3}{#4}{#5}\ensuremath{#2#3#4#5}}
  \newcommand{\acontraction@@}[3][0.05em]{%
  % the 1st parameter (explicitly inserted) is the width
  % of the contraction line
  \hbox{%
    \vrule width 0pt height 0pt depth #3%
    \vrule width #2 height 0pt depth #1%
    \vrule width 0pt height 0pt depth #3%
    \relax%
  }
}
% contraction below the expression
% ----
\newcommand{\bcontraction}[5][1ex]{%
\mathchoice
  {\bcontraction@\displaystyle{#2}{#3}{#4}{#5}{#1}}%
  {\bcontraction@\textstyle{#2}{#3}{#4}{#5}{#1}}%
  {\bcontraction@\scriptstyle{#2}{#3}{#4}{#5}{#1}}%
  {\bcontraction@\scriptscriptstyle{#2}{#3}{#4}{#5}{#1}}}%
\newcommand{\bcontraction@}[6]{%
  \setbox\swb@xone=\hbox{${}#1{}#2{}$}%
  \setbox\swb@xtwo=\hbox{${}#1{}#3{}$}%
  \setbox\swb@xthree=\hbox{${}#1{}#4{}$}%
  \setbox\swb@xfour=\hbox{${}#1{}#5{}$}%
  \swdimen@ne=\wd\swb@xtwo%
  \advance\swdimen@ne by \wd\swb@xfour%
  \divide\swdimen@ne by 2%
  \advance\swdimen@ne by \wd\swb@xthree%
  \lower 0.5ex \vbox{%
    \hbox to 0pt{%
      \kern \wd\swb@xone%
      \kern 0.5\wd\swb@xtwo%
      \bcontraction@@{\swdimen@ne}{#6}%
      \hss%
    }%
  }%
}
\newcommand{\bcontracted}[5][0.5ex]{%
  \bcontraction[#1]{#2}{#3}{#4}{#5}\ensuremath{#2#3#4#5}}
\newcommand{\bcontraction@@}[3][0.05em]{%
% the 1st parameter (explicitly inserted) is the width
% of the contraction line
  \hbox{%
    \swdimentw@=#3
    \advance\swdimentw@ by -#1
    \vrule width 0pt height 0pt depth #3% 
    \lower\swdimentw@\hbox{\vrule width #2 height 0pt depth #1}%
    \vrule width 0pt height 0pt depth #3%
    \relax%
  }%
}
\makeatother

\begin{document}

\[
  \bcontraction[0,2ex]{}{A}{B}{C}
  \bcontraction[0,2ex]{ABCDE}{F}{G}{H}
  \acontraction[0.3ex]{AB}{D}{DE}{F}
  \acontraction[0.3ex]{ABCDEFG}{H}{I}{J}
  ABCDEFGHIJ
\]

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
vmarko
Posts: 4
Joined: Sat Oct 16, 2010 5:02 pm

Re: Intersecting arguments

Post by vmarko »

Wow, I'm impressed! :-) It works in the same way as simplewick, I guess it will do what I need. And no, I'm not using simplewick itself, no need for compatibility.

Thanks a lot! :-)
Marko
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Intersecting arguments

Post by localghost »

vmarko wrote:[…] This is my first post to this forum, so please don't mind if I don't know appropriate etiquette here. […]
You could have avoided this by reading the Board Rules before posting. There you can also learn how to mark a topic as solved.


Best regards and welcome to the board
Thorsten
Post Reply