2

I am trying to use the ConTeXt command \inframed to add a border to arbitrary text within a line/paragraph. MWE to show problem:

\starttext
a \inframed{b} c
\blank
\inframed{d} e
\stoptext

Expected output: "d" and "e" appear on same line, as with "a", "b", and "c".

Actual output: line break after "d".

Sample output

Is this supposed to happen, and in either case, what can be done to prevent it? The ConTeXt Wiki pages on the "(in)framed" command and a Google search yielded no leads.

3

This behaviour has nothing to do with ConTeXt actually, but a is a consequence of the fact that a box cannot start a paragraph. There are several possibilities to force a paragraph. Some suggestions are also given in the Garden.

  1. Don’t start the paragraph with a box.

    \starttext
    a \inframed{b} c
    \stoptext
    

    enter image description here

  2. Force TeX to switch to horizontal mode. This can be done by either \dontleavehmode or \leavevmode. Recommended is \dontleavehmode because it does not check for vmode before doing the switch and has therefore slightly better performance.

    \starttext
    \dontleavehmode\inframed{b} c
    \stoptext
    

    enter image description here

  3. Explicitly place the indentation box.

    \starttext
    \indent\inframed{b} c
    \stoptext
    

    enter image description here

I’m sure there are more methods but these are the ones which came to my mind immediately.


After reading your comment I thought that you be interested in this:

\definetextbackground
  [framedsnippet]
  [
    background=,
    framecolor=black,
    location=text,
  ]

\starttext

Hello World!
\starttextbackground[framedsnippet]
This is a very long sentence spanning several lines to show off that
\type{textbackground} can span accross lines.
\stoptextbackground\ % <- We need this to avoid skipping spaces
Goodbye World!

\stoptext

enter image description here

  • Okay. Really, what I want is to be able to use the same command anywhere within a paragraph to add a border to a short string of text. (Will update the question.) So would custom command with \inframed preceded by \dontleavehmode as in #2 always work? – Kenneth Hanson Feb 28 '17 at 13:45
  • Also, I wonder if it might be good to include @MarcoDaniel's reference, or at least mention "vertical mode" explicitly, because this completely unobvious to those (like me) who don't know plain TeX. – Kenneth Hanson Feb 28 '17 at 13:55
  • @KennethHanson As for a reference, this has already been discussed on TeX.SX: tex.stackexchange.com/questions/22852/… and tex.stackexchange.com/questions/118164/… – Henri Menke Feb 28 '17 at 14:06
  • Thanks. This \definetextbackground doesn't appear in the manual and is hardly mentioned anywhere, but looks promising. – Kenneth Hanson Mar 2 '17 at 10:46
  • 1
    @KennethHanson wiki.contextgarden.net/TextBackground – Henri Menke Mar 2 '17 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.