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.

This follows a previous post which can be found here.
I'm now trying to used that command but I get lots of compilation mistakes and I really don't understand where the problem comes from. This is how I'm using the command:

\documentclass{article}
\usepackage{mathtools}
\newcommand{\twopartdef}[3]{%
   \left\{
      \begin{array}{ll}
          #1 & \mbox{if } #2 \\
          #3 & \mbox{otherwise}
      \end{array}
   \right.
}
\begin{document}
 %some text ...
 \[
 join^\sharp_{KSet_n}(\{ \alpha_1, \hdots, \alpha_p \}, \{ \beta_1, \hdots, \beta_q \}) = 
\twopartdef{\{\alpha_1, \hdots, \alpha_p\} \cup \{\beta_1, \hdots, \beta_q\}}{p \leq n et q \leq n}{\top} 
\]
 %more text
\end{document}

Here are the main compilation errors:

Missing $ inserted
I've inserted a begin-math/end-math symbol since I think you left one out
....
I've deleted a group-closing symbol because it seems to be spurious, as in `$x}$'..
....
I can't figure out why you would want to use a tab mark here.
....
A left brace was mandatory here, so I've put one in.
....

I found that the problem is from this line (by commenting it)

\twopartdef{\{\alpha_1, \hdots, \alpha_p\} \cup \{\beta_1, \hdots, \beta_q\}}{p \leq n et q \leq n}{\top}

So I tried to put $ $, lbrace rbrace instead of \{ \} but it didn't change anything. I've used the same command for other definition and it work fine. What am I missing?

Edit: I tried compiling the code above alone and it worked. So why doesn't it work with the remaining document?

share|improve this question
2  
Pleas post an entire minimal example (not just code snippets) that one can copy and paste into your editor and compile. At least one reason for this is that you don't specify the "version" of \twopartdef that you use. Also there's no formal definition given \hdots. –  Werner Jul 20 '12 at 15:35
    
I don't get any error with the example you added, but only an "Overfull \hbox" message. –  egreg Jul 20 '12 at 17:33
    
How can I post my full code? Its strange because that line produces error in the full code. Maybe having a look at it will help.. –  Joseph Elcid Jul 20 '12 at 17:39
add comment

2 Answers

up vote 5 down vote accepted

Your definition of \twopartdef makes for a very heavy syntax.

\documentclass{article}
\usepackage{mathtools}

\newcommand{\case}[1]{\text{if $#1$}}
\newcommand{\otherwise}{\text{otherwise}}
\newenvironment{multipartdef}
  {\begin{cases}}
  {\end{cases}}

\DeclareMathOperator{\join}{join}

\begin{document}
 %some text ...
 \[
\join^\sharp_{\mathit{KSet}_n}(\{ \alpha_1, \dots, \alpha_p \}, \{ \beta_1, \dots, \beta_q \}) = 
\begin{multipartdef}
\{\alpha_1, \hdots, \alpha_p\} \cup \{\beta_1, \hdots, \beta_q\} &
  \case{p \leq n \text{ and } q \leq n}
\\
\top & \otherwise
\end{multipartdef}
\]
 %more text
\end{document}

If you have more cases, you won't need different commands, but only to add lines to the environment. You have also less chances to get errors.

share|improve this answer
    
But why was my definition producing errors? –  Joseph Elcid Jul 20 '12 at 18:02
    
@JosephElcid It doesn't. At least the example you posted. –  egreg Jul 20 '12 at 18:05
add comment

I assume you are using this definition for \twopartdef:

\usepackage{amsmath}
\newcommand{\twopartdef}[3]{%
  \begin{cases}
    #1 & \text{if #2} \\
    #3 & \text{otherwise}
  \end{cases}
}

this definition treats the second argument in text mode, so you need to write

$p \leq n$ et $q \leq n$

in the second argument of the command in your code (otherwise, the firs \leq will appear in text mode and this will trigger the error message).

Your corrected code:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\twopartdef}[3]{%
  \begin{cases}
    #1 & \text{if #2} \\
    #3 & \text{otherwise}
  \end{cases}
}
\DeclareMathOperator{\join}{join}

\begin{document}

\[
 \join^\sharp_{KSet_n}(\{ \alpha_1, \hdots, \alpha_p \}, \{ \beta_1, \hdots, \beta_q \}) = 
\twopartdef{\{\alpha_1, \hdots, \alpha_p\} \cup \{\beta_1, \hdots, \beta_q\}}{$p \leq n$ et $q \leq n$}{\top} 
\]

\end{document}

And the result:

enter image description here

Notice that I used \DeclareMathOperator to define the operator \join that admits super/subscripts (in a similar fashion to \sum).

share|improve this answer
add comment

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.