[Tex/LaTex] Flushleft and flushright in the same line (ConTeXt)

contexthorizontal alignment

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?

Best Answer

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