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'm often experiencing instances, when I need to define a function on two sets in a domain. I'd like to create a command \newcommand{\func}[4]{...}, which makes an inline bracket, that shows how the function maps both sets of points.

So far, I've managed to do this

enter image description here

via the command $\binom{\tiny(x,s,t)\mapsto(x,s(1-t))}{\tiny(y,t)\mapsto y~~~~~~~~~}. As you can see, I'm having problems with the alignment of both \mapstos and also with the size of the both outer brackets.

Could anyone please help me write such a command? I tried it with an inline table, but it is way too large. It would be desirable (but not necessary) that both outer brackets would respond to \left and \right or \big.

COMMENT: this is how my current solution (via \binom with no alignment) looks like:

enter image description here

Any solution that produces larger brackets is not acceptable. The only thing that is missing is alignment.

share|improve this question

5 Answers 5

up vote 1 down vote accepted

Ideally, one would have a version of aligned with smaller spacing. I'm not aware of any implementation of that though.

Here is a non-automatic solution with \mathllap and psmallmatrix* from mathtools:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
abc 
$\begin{psmallmatrix*}[l]
    (x,s,t)                           \mapsto (x,s(1-t)) \\ 
    \phantom{(x,s,t)}\mathllap{(y,t)} \mapsto y
\end{psmallmatrix*}$
abc
\end{document}

result

share|improve this answer
    
@Caramdir: LaTeX Error: Environment psmallmatrix* undefined! –  Leon Lampret May 6 '11 at 23:16
    
and this is still quite large, looks larger than \binom –  Leon Lampret May 6 '11 at 23:22
    
how do people in algebra write inline permutations? those are aligned –  Leon Lampret May 6 '11 at 23:23
    
@Leon: Did you include mathtools (this probably needs a recent version)? Smaller text would be unreadable. You could get smaller brackets by using smallmatrix* (without p) and putting in brackets of your own, but imo the brackets in your example are too small. –  Caramdir May 6 '11 at 23:58
    
@Caramdir: Last request, I promise: the main problem are the brackets inside. If you zoom in, you can see that in (x,s,t), the bracket is by far the tallest symbol, taking most of the space. How can I use some other type of braces inside this command, that are only as tall as the largest symbol? –  Leon Lampret May 7 '11 at 1:49

Here's an option, building on Tobi's answer. Now the command offers three different sizes depending on the first (optional argument): with no optional argument, it can be used in in-line expressions; using Big or bigg as the optional argument, you can increase the size and use the command in displayed expressions.

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{ifthen}
\usepackage{amsmath,mathtools}

% default values
\newcommand\OpenS{\bigl(}
\newcommand\CloseS{\bigr)}
\newcommand\Vspace{-0.85em}
\newcommand\Msize{\scriptstyle}

\newcommand{\func}[5][]{%
  \ensuremath{% 
    \ifthenelse{\equal{#1}{Big}}
      {\renewcommand\OpenS{\Bigl(}%
        \renewcommand\CloseS{\Bigr)}%
        \renewcommand\Vspace{-0.55em}%
        \renewcommand\Msize{\textstyle}}%
      {\ifthenelse{\equal{#1}{bigg}}%
        {\renewcommand\OpenS{\biggl(}%
          \renewcommand\CloseS{\biggr)}%
          \renewcommand\Vspace{-0.2em}%
          \renewcommand\Msize{\displaystyle}}%
          {}}
          \OpenS%
            \begin{aligned}\Msize
            {\Msize#2} &\mapsto {\Msize#3}\\[\Vspace]
            {\Msize#4} &\mapsto {\Msize#5}
            \end{aligned}
        \CloseS%
    }%
}

\begin{document}
text text  text text t text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text text text $k(g)=\func{(x,s,t)}{(x,s(t-1))}{(y,t)}{y}$ text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  
\[
k(g)=\func[Big]{(x,s,t)}{(x,s(t-1))}{(y,t)}{y}
\]
text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text 
\[
k(g)=\func[bigg]{(x,s,t)}{\big(x,s(t-1)\big)}{(y,t)}{y}
\]
text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text text  text text 

\end{document}

The result:

share|improve this answer

Try this (note that you’ll need the amsmath-package):

\documentclass[11pt,a4paper]{scrartcl}
\usepackage{amsmath}
\newcommand{\func}[4]{%
    \ensuremath{%
        \left(%
            \begin{aligned}
            #1 &\rightarrow #2\\
            #3 &\rightarrow  #4
            \end{aligned}
        \right)%
    }%
}

\begin{document}
\[k(g)=\func{abcd}{ef}{gh}{ijklm}\]
\end{document}

output:
output

You just have to replace the arrows …

share|improve this answer
    
way too large to be inline. This is much larger than \binom –  Leon Lampret May 6 '11 at 22:44
    
@Leon I don’t believe, that somebody likes to read an construct like this inline ;). If you like you can wrap it in an \resizebox from the graphicx-package –  Tobi May 6 '11 at 22:47
    
The things that I'm writing are fairly simple functions (concrete homotopies). It's much more readable, if it's written in this way. –  Leon Lampret May 6 '11 at 22:51
1  
@Leon, Tobi: you can shrink this by putting \scriptstyle in front of each of the four parts, and putting \\[-10pt] for the line break. The number may need tuning. Also, use \bigl(...\bigr) for the braces and it looks pretty inline to me. –  Ryan Reich May 6 '11 at 23:31

This is a streamlined version of Gonzalo's answer

\makeatletter
\newcommand{\ho@func}[8]{
  %#1 = opening delimiter
  %#2 = closing delimiter
  %#3 = vertical space 
  %#4 = size of symbols
  %#5 = top left
  %#6 = top right
  %#7 = bottom left
  %#8 = bottom right
  #1\vcenter{\halign{\hfil$##\mapsto{}$&$##$\hfil\cr
    #4#5&#4#6\cr\noalign{\vskip#3}#4#7&#4#8\cr}}#2}
\@namedef{ho@}{\ho@func{\bigl(}{\bigr)}{-1ex}{\scriptstyle}}
\@namedef{ho@Big}{\ho@func{\Bigl(}{\Bigr)}{-.2ex}{\textstyle}}
\@namedef{ho@bigg}{\ho@func{\biggl(}{\biggr)}{0ex}{\textstyle}}
\newcommand{\func}[1][]{\@nameuse{ho@#1}}
\makeatother

The optional argument to \func decides which one of the \ho@... commands to use; the command \ho@... expands to \ho@func followed by four of the eight arguments it requires, the following four are in the input stream,where they appear to the user as arguments to \func.

I too, as Phil, would never define such a thing using \ensuremath: putting math formulas where they belong helps to confine syntax errors.

Note: edited to use directly \halign. The example text can be the same as in Gonzalo's answer, no extra package is needed.

share|improve this answer
    
Thank you, but I'm afraid this is too complicated for me. Especially since I've found a better solution (I think). I can't post it yet, I have to wait 8hrs, not enough reputation points. –  Leon Lampret May 7 '11 at 0:44
    
@Leon: You don't need to understand the definitions, just to use them. :) The example text may be the same as Gonzalo's. –  egreg May 7 '11 at 7:34

Here's a version using Xy-pic:

\documentclass[12pt]{article}
\usepackage[all,cmtip]{xy}

\newcommand{\func}[4]{
  \begingroup
  \let\objectstyle=\scriptstyle
  \ensuremath{
    \left(
      \vcenter{
        \xymatrix@R=0ex@C=1em{
          {#1} \ar@{|->}[r]& {#2}\\
          {#3} \ar@{|->}[r]& {#4}
        }
      }
    \right)
  }
  \endgroup
}

\begin{document}

Here we are in math mode: $\func{(x,y)}{x+y}{(s,t)}{s^{2}-t}$

Here we are not in math mode: \func{(x,s,t)}{(x,s(1-t))}{(y,t)}{y}

\end{document}

(I would never have thought of using \ensuremath, but I saw it in @Tobi's answer.) enter image description here

share|improve this answer

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.