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 tried to write a macro for typesetting semantic denotations, using the stmaryrd package, but there are a few issues that I would like to resolve. My first attempt at the macro was the following:

\documentclass{article}
\usepackage{stmaryrd}
\newcommand{\den}[2][]{$\llbracket$#2$\rrbracket^{#1}$}
\begin{document}
\den[w,g]{example} = \ldots
\end{document}

The issue that I would like to resolve is that, in some instances, the text between the denotation brackets gets lengthy and is hard to look at since it runs across multiple lines. (It seems that I can't insert a picture yet, but it looks something like the following.)

[[This is a purposefully long sentence whose denotation I wish to specify, but because it is so long it runs across multiple lines and ends up being both really hard to read and pretty gross, aesthetically speaking]] = . . .

Now, the stmaryrd is written such that \llbracket and \rrbracket are delimiters, so then I tried this:

\documentclass{article}
\usepackage{stmaryrd}
\newcommand{\den}[2][]{
\[
\left\llbracket#2\right\rrbracket^{#1}
\]
}
\begin{document}
\den{example}
\end{document}

I'm not too familiar with delimiters, but it seems you cannot insert line breaks between the \left and \right commands, so there is no way of breaking the text inside of the brackets across multiple lines. This second attempt also centers the denotation and italicizes the text inside of the brackets, two things that I do not want to happen.

With regard to the first issue, is there some way to limit the horizontal space of the text inside of the brackets, perhaps with a \parbox command? The text would then have to wrap inside of the limited horizontal space, of course, but this is something I have no idea how to do myself. And, ideally, the size of the horizontal space would then be an optional argument of the new \den command, so that it could either be specified or scaled when necessary.

share|improve this question
1  
Welcome to TeX.SX! –  Papiro Jun 28 '13 at 16:54

2 Answers 2

up vote 4 down vote accepted

I would do this a slightly different way (taking on your suggestion of a \parbox). I've created a second command to wrap a long denotation. You can then use this as needed to wrap longer denotations to a specified width (I've set a default width of 1in). I've also used the ragged2e package to wrap the long texts with a ragged margin and hyphenation, and also put the entire argument of the denotation in the amsmath \text command so that the text is in roman and not math italic. Finally, by using inline mode instead of displaymath, we can left align the denotations for use with an example environment.

Update

I've used the varwidth package to set the wrapped text in a box its natural width. Thanks to David Carlisle for telling me about this package. I've also put the examples with a gb4e example to show what they would look like.

\documentclass{article}
\usepackage{stmaryrd}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{varwidth}
\newcommand{\den}[2][]{
\(
\left\llbracket\;\text{#2}\;\right\rrbracket^{#1}
\)
}

\newcommand{\wraptext}[2][1in]{\begin{varwidth}{#1}{\RaggedRight#2}\end{varwidth}}
\begin{document}
\den[\alpha]{\wraptext[3in]{example of a really long denotation which will continue as long as we like}}
\den[\alpha]{\wraptext[2in]{example of a really long denotation which will continue as long as we like}}

\den[\alpha]{a smaller one}
\end{document}

output of code

share|improve this answer
    
This is more or less perfect; thanks. I messed around with it a little bit, and there only seems to be one minor issue. I'm not sure if it is something that can easily be resolved or not. But, if you use your exact MWE and set the optional \wraptext argument to 3in in the "example of a really long denotation which will continue as long as we like", the right bracket is offset because of how the text wraps. Any ideas? If not, it works well and the width can be manually manipulated until it works out. –  Adam Liter Jun 28 '13 at 20:42
    
@Adam Thanks for pointing that out. See my updated answer. –  Alan Munn Jun 28 '13 at 21:00

A simple implementation could be

\documentclass{article}

\usepackage{stmaryrd}

\newcommand\den[2][]{%
  \ensuremath{%
    \left\llbracket
    \begin{tabular}{@{}l@{}}
    #2
    \end{tabular}
    \right\rrbracket^{#1}}}

\begin{document}

Test \den{foo} and
\[
  \den[\beta]{some text\\ others} = \Gamma
\]

\end{document}

A tabular environment provides the ability to (explicitly) break lines as you wish. So you don't need to specify the width of the text.

enter image description here

There are certainly more possibilities, but I believe this simple implementation is easy to understand. If you have more requirements, let me know.

share|improve this answer
    
Is there a way of implementing the marco so that you actually can specify the horizontal width of the text as an argument of the command and then have the text wrap? It would be ideal for my purposes, since these expressions are often embedded in nested list environments using the gb4e package, for example. Being able to specify such a parameter in the \den command would ultimately be more useful than having to insert line breaks by hand each time. Also, is there some way to prevent the output from being centered? Is that a result of embedding it inside \[ and \]? –  Adam Liter Jun 28 '13 at 19:40

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.