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 have the following macro

\mainlanguage   [de]
\definepapersize[MyBook][A5]
\setuppapersize[MyBook][A5]

\definestartstop[Test][commands=\setups{Test}]
\def\Test{\doTest}
\def\Test[#1]{  
    \placeongrid[top]{
        {\startalignment [flushleft] #1 \stopalignment \startalignment [flushright] (\bf Test Message) \stopalignment}
    \blank[big]
    }
}

\starttext
\Test[Wrong]
\Test[This one is correct, correct, correct, correct, correct.]
This one is wrong, wrong, wrong, wrong, wrong.
\startalignment [flushright] 
(\bf Test Message) 
\stopalignment

\stoptext

with three examples. What I want is this:

\Test[#1] should produce #1 and #2 with the following properties:

  • #1 should be flushleft, #2 flushright
  • #2 should never be breaked into two lines
  • if they fit into one line, then they should do that, not like the above first example

How to do that?

share|improve this question
    
What if #1 or #2 is larger than a line? What if #1 + #2 is larger than a line. If you ignore these cases then \hbox to \textwidth{#1 \hfill #2} should work. –  Aditya Nov 1 '12 at 16:28
    
The only precondition is: #2 is smaller than a line. But #1 may be much larger, in any cases #1 should be flushleft and #2 should be flushright. And #2 should be in the last line of #1, if there is space for it. If not, then #2 has to be in the next line. –  Mustafa Nov 2 '12 at 11:47
2  
Are you trying to write attribution for quotes? Simply using \wordright{#2} should be sufficient. –  Aditya Nov 2 '12 at 12:25
    
Indeed, that is it! –  Mustafa Nov 2 '12 at 14:43

1 Answer 1

I am using the annotation module for a better key-value driven syntax (although you can also use \definestartstop). You can use \wordright{...} to place a word on the right. For example:

\usemodule[annotation]

\defineannotation
  [Quote]
  [
    alternative=command,
    spacebefore=big,
    spaceafter=big,
    command=\PlaceQuote,
  ]

\define[2]\PlaceQuote
  {\startalignment[flushleft]
     \placeannotationcontent
    \stopalignment
    \blank[samepage]
    \wordright{\placeannotationtitle}}


\setuppapersize[A5]

\starttext

\input ward

\startQuote[title={Donald Knuth}]
  \input knuth
\stopQuote

\input ward

\stoptext

gives

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.