ConTeXt: Frame a Sentence












6















How can I frame a single sentence in a paragraph when the sentence may wrap around to become several lines long? Just like color but to also provide background color, frame, styling, and so forth. The idea is to provide a formatting for inline code that unlike type ignores input whitespace.





  • color works fine but only sets the foreground color


  • framed doesn't wrap


  • type wraps but only sets the foreground color. Also unlike color doesn't ignore input whitespace.


  • start...stoptextbackground forces a new block even when used as left= and right= arguments to setuptype.


  • framed doesn't actually wrap the input to type when used like:



    setuptype[command=mtc]
    define[1]mtc{%
    dontleavehmode{framed[frame=on,
    background=color,
    background-color=orange,
    ]{#1}}}



This is what I mean by "ignore input whitespace":



setuptype[color=red,style=tf]
starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been type{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.


Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been color[red]{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
stoptext


Clarify "ignore input whitespace". Notice the unintentional whitespace in the first paragraph.



Though I guess it doesn't matter since I can do this, based on the accepted answer:



definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]

starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been starttextbackground[mtcframed]the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuriesstoptextbackground, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
stoptext


Using <code>starttextbackground</code> without <code>type</code>, inline within a block



And then define a new macro for consistency with other style commands:



define[1]mtc{starttextbackground[mtcframed]#1stoptextbackground}


Edit:



There are minor overfull box issues in English as well. To be fair this is related only to the use of monotype fonts. Unfortunately it is very noticeable as the text spills out of the frame. How can I fix this? For example, with either approach:



unprotect
defineinterfacevariable{collapse}{collapse}
setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
protect

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]

define[1]mtcA{starttextbackground[mtcframed]tt#1stoptextbackground}

definetype[mtcB]
[space=collapse,
left={starttextbackground[mtcframed]},
right={stoptextbackground},
]


Demonstrate how, with either approach, text overflows the frame



Also is there any reason to prefer definetype[...][space=collapse...] over define[1]mtc{...}? The former is interesting and useful but seems overly complex.










share|improve this question

























  • Use definetype[mtc][space=stretch] to get the regular interword glue. I have also updated my answer.

    – Henri Menke
    Dec 1 '18 at 6:44











  • For me it doesn't spill out the frame. Are you using the latest beta?

    – Henri Menke
    Dec 2 '18 at 7:58











  • The other problem is that hyphenation is by default switched off for teletype fonts, because you usually use those for code and hyphenation doesn't make sense there.

    – Henri Menke
    Dec 2 '18 at 8:00













  • Hyphenation is disabled for type, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph using tt I actually have more hyphenation than without. As for type setting lines=hyphenated doesn't influence the overflow.

    – user19087
    Dec 2 '18 at 15:34











  • I'm using the ConTeXt standalone beta 2018.10.18.

    – user19087
    Dec 2 '18 at 15:34
















6















How can I frame a single sentence in a paragraph when the sentence may wrap around to become several lines long? Just like color but to also provide background color, frame, styling, and so forth. The idea is to provide a formatting for inline code that unlike type ignores input whitespace.





  • color works fine but only sets the foreground color


  • framed doesn't wrap


  • type wraps but only sets the foreground color. Also unlike color doesn't ignore input whitespace.


  • start...stoptextbackground forces a new block even when used as left= and right= arguments to setuptype.


  • framed doesn't actually wrap the input to type when used like:



    setuptype[command=mtc]
    define[1]mtc{%
    dontleavehmode{framed[frame=on,
    background=color,
    background-color=orange,
    ]{#1}}}



This is what I mean by "ignore input whitespace":



setuptype[color=red,style=tf]
starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been type{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.


Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been color[red]{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
stoptext


Clarify "ignore input whitespace". Notice the unintentional whitespace in the first paragraph.



Though I guess it doesn't matter since I can do this, based on the accepted answer:



definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]

starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been starttextbackground[mtcframed]the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuriesstoptextbackground, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
stoptext


Using <code>starttextbackground</code> without <code>type</code>, inline within a block



And then define a new macro for consistency with other style commands:



define[1]mtc{starttextbackground[mtcframed]#1stoptextbackground}


Edit:



There are minor overfull box issues in English as well. To be fair this is related only to the use of monotype fonts. Unfortunately it is very noticeable as the text spills out of the frame. How can I fix this? For example, with either approach:



unprotect
defineinterfacevariable{collapse}{collapse}
setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
protect

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]

define[1]mtcA{starttextbackground[mtcframed]tt#1stoptextbackground}

definetype[mtcB]
[space=collapse,
left={starttextbackground[mtcframed]},
right={stoptextbackground},
]


Demonstrate how, with either approach, text overflows the frame



Also is there any reason to prefer definetype[...][space=collapse...] over define[1]mtc{...}? The former is interesting and useful but seems overly complex.










share|improve this question

























  • Use definetype[mtc][space=stretch] to get the regular interword glue. I have also updated my answer.

    – Henri Menke
    Dec 1 '18 at 6:44











  • For me it doesn't spill out the frame. Are you using the latest beta?

    – Henri Menke
    Dec 2 '18 at 7:58











  • The other problem is that hyphenation is by default switched off for teletype fonts, because you usually use those for code and hyphenation doesn't make sense there.

    – Henri Menke
    Dec 2 '18 at 8:00













  • Hyphenation is disabled for type, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph using tt I actually have more hyphenation than without. As for type setting lines=hyphenated doesn't influence the overflow.

    – user19087
    Dec 2 '18 at 15:34











  • I'm using the ConTeXt standalone beta 2018.10.18.

    – user19087
    Dec 2 '18 at 15:34














6












6








6








How can I frame a single sentence in a paragraph when the sentence may wrap around to become several lines long? Just like color but to also provide background color, frame, styling, and so forth. The idea is to provide a formatting for inline code that unlike type ignores input whitespace.





  • color works fine but only sets the foreground color


  • framed doesn't wrap


  • type wraps but only sets the foreground color. Also unlike color doesn't ignore input whitespace.


  • start...stoptextbackground forces a new block even when used as left= and right= arguments to setuptype.


  • framed doesn't actually wrap the input to type when used like:



    setuptype[command=mtc]
    define[1]mtc{%
    dontleavehmode{framed[frame=on,
    background=color,
    background-color=orange,
    ]{#1}}}



This is what I mean by "ignore input whitespace":



setuptype[color=red,style=tf]
starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been type{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.


Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been color[red]{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
stoptext


Clarify "ignore input whitespace". Notice the unintentional whitespace in the first paragraph.



Though I guess it doesn't matter since I can do this, based on the accepted answer:



definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]

starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been starttextbackground[mtcframed]the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuriesstoptextbackground, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
stoptext


Using <code>starttextbackground</code> without <code>type</code>, inline within a block



And then define a new macro for consistency with other style commands:



define[1]mtc{starttextbackground[mtcframed]#1stoptextbackground}


Edit:



There are minor overfull box issues in English as well. To be fair this is related only to the use of monotype fonts. Unfortunately it is very noticeable as the text spills out of the frame. How can I fix this? For example, with either approach:



unprotect
defineinterfacevariable{collapse}{collapse}
setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
protect

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]

define[1]mtcA{starttextbackground[mtcframed]tt#1stoptextbackground}

definetype[mtcB]
[space=collapse,
left={starttextbackground[mtcframed]},
right={stoptextbackground},
]


Demonstrate how, with either approach, text overflows the frame



Also is there any reason to prefer definetype[...][space=collapse...] over define[1]mtc{...}? The former is interesting and useful but seems overly complex.










share|improve this question
















How can I frame a single sentence in a paragraph when the sentence may wrap around to become several lines long? Just like color but to also provide background color, frame, styling, and so forth. The idea is to provide a formatting for inline code that unlike type ignores input whitespace.





  • color works fine but only sets the foreground color


  • framed doesn't wrap


  • type wraps but only sets the foreground color. Also unlike color doesn't ignore input whitespace.


  • start...stoptextbackground forces a new block even when used as left= and right= arguments to setuptype.


  • framed doesn't actually wrap the input to type when used like:



    setuptype[command=mtc]
    define[1]mtc{%
    dontleavehmode{framed[frame=on,
    background=color,
    background-color=orange,
    ]{#1}}}



This is what I mean by "ignore input whitespace":



setuptype[color=red,style=tf]
starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been type{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.


Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been color[red]{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
stoptext


Clarify "ignore input whitespace". Notice the unintentional whitespace in the first paragraph.



Though I guess it doesn't matter since I can do this, based on the accepted answer:



definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]

starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been starttextbackground[mtcframed]the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuriesstoptextbackground, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
stoptext


Using <code>starttextbackground</code> without <code>type</code>, inline within a block



And then define a new macro for consistency with other style commands:



define[1]mtc{starttextbackground[mtcframed]#1stoptextbackground}


Edit:



There are minor overfull box issues in English as well. To be fair this is related only to the use of monotype fonts. Unfortunately it is very noticeable as the text spills out of the frame. How can I fix this? For example, with either approach:



unprotect
defineinterfacevariable{collapse}{collapse}
setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
protect

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]

define[1]mtcA{starttextbackground[mtcframed]tt#1stoptextbackground}

definetype[mtcB]
[space=collapse,
left={starttextbackground[mtcframed]},
right={stoptextbackground},
]


Demonstrate how, with either approach, text overflows the frame



Also is there any reason to prefer definetype[...][space=collapse...] over define[1]mtc{...}? The former is interesting and useful but seems overly complex.







formatting context backgrounds






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 2 '18 at 7:25







user19087

















asked Dec 1 '18 at 3:27









user19087user19087

3368




3368













  • Use definetype[mtc][space=stretch] to get the regular interword glue. I have also updated my answer.

    – Henri Menke
    Dec 1 '18 at 6:44











  • For me it doesn't spill out the frame. Are you using the latest beta?

    – Henri Menke
    Dec 2 '18 at 7:58











  • The other problem is that hyphenation is by default switched off for teletype fonts, because you usually use those for code and hyphenation doesn't make sense there.

    – Henri Menke
    Dec 2 '18 at 8:00













  • Hyphenation is disabled for type, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph using tt I actually have more hyphenation than without. As for type setting lines=hyphenated doesn't influence the overflow.

    – user19087
    Dec 2 '18 at 15:34











  • I'm using the ConTeXt standalone beta 2018.10.18.

    – user19087
    Dec 2 '18 at 15:34



















  • Use definetype[mtc][space=stretch] to get the regular interword glue. I have also updated my answer.

    – Henri Menke
    Dec 1 '18 at 6:44











  • For me it doesn't spill out the frame. Are you using the latest beta?

    – Henri Menke
    Dec 2 '18 at 7:58











  • The other problem is that hyphenation is by default switched off for teletype fonts, because you usually use those for code and hyphenation doesn't make sense there.

    – Henri Menke
    Dec 2 '18 at 8:00













  • Hyphenation is disabled for type, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph using tt I actually have more hyphenation than without. As for type setting lines=hyphenated doesn't influence the overflow.

    – user19087
    Dec 2 '18 at 15:34











  • I'm using the ConTeXt standalone beta 2018.10.18.

    – user19087
    Dec 2 '18 at 15:34

















Use definetype[mtc][space=stretch] to get the regular interword glue. I have also updated my answer.

– Henri Menke
Dec 1 '18 at 6:44





Use definetype[mtc][space=stretch] to get the regular interword glue. I have also updated my answer.

– Henri Menke
Dec 1 '18 at 6:44













For me it doesn't spill out the frame. Are you using the latest beta?

– Henri Menke
Dec 2 '18 at 7:58





For me it doesn't spill out the frame. Are you using the latest beta?

– Henri Menke
Dec 2 '18 at 7:58













The other problem is that hyphenation is by default switched off for teletype fonts, because you usually use those for code and hyphenation doesn't make sense there.

– Henri Menke
Dec 2 '18 at 8:00







The other problem is that hyphenation is by default switched off for teletype fonts, because you usually use those for code and hyphenation doesn't make sense there.

– Henri Menke
Dec 2 '18 at 8:00















Hyphenation is disabled for type, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph using tt I actually have more hyphenation than without. As for type setting lines=hyphenated doesn't influence the overflow.

– user19087
Dec 2 '18 at 15:34





Hyphenation is disabled for type, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph using tt I actually have more hyphenation than without. As for type setting lines=hyphenated doesn't influence the overflow.

– user19087
Dec 2 '18 at 15:34













I'm using the ConTeXt standalone beta 2018.10.18.

– user19087
Dec 2 '18 at 15:34





I'm using the ConTeXt standalone beta 2018.10.18.

– user19087
Dec 2 '18 at 15:34










1 Answer
1






active

oldest

votes


















9














start...stoptextbackground is the correct thing to do but you have to set location=text. To collapse interword spaces, I define a new spacing method collapse and use it in setuptype. I also add a little bit of stretch and shrink to the interword space for better linebreaking.



% The original version, which only collapses interword spaces.
%unprotect
%defineinterfacevariable{collapse}{collapse}
%setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
%protect

% The updated version, which in addition adds stretch and shrink
unprotect
defineinterfacevariable{collapse}{collapse}
setvalue
{??typingspacev!collapse}%
{defobeyedspace{unskip
hskipinterwordspace
plus .5interwordspace
minus .5interwordspacerelax}}
protect

definetype
[mtc]
[left={starttextbackground[mtcframed]},
right={stoptextbackground},
space=collapse]

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text]

starttext

Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been mtc{the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book. It has survived
not only five centuries}, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.

stoptext


enter image description here






share|improve this answer


























  • +1: Great answer. LaTeX (and the contributors here) keep to amaze me.

    – Dr. Manuel Kuehner
    Dec 5 '18 at 22:55











  • Why use type? Isn't it better to simply set style=mono

    – Aditya
    Dec 6 '18 at 3:00











  • @Aditya In this case yes, but OP wants to use this to typeset code.

    – Henri Menke
    Dec 6 '18 at 3:09











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462652%2fcontext-frame-a-sentence%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









9














start...stoptextbackground is the correct thing to do but you have to set location=text. To collapse interword spaces, I define a new spacing method collapse and use it in setuptype. I also add a little bit of stretch and shrink to the interword space for better linebreaking.



% The original version, which only collapses interword spaces.
%unprotect
%defineinterfacevariable{collapse}{collapse}
%setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
%protect

% The updated version, which in addition adds stretch and shrink
unprotect
defineinterfacevariable{collapse}{collapse}
setvalue
{??typingspacev!collapse}%
{defobeyedspace{unskip
hskipinterwordspace
plus .5interwordspace
minus .5interwordspacerelax}}
protect

definetype
[mtc]
[left={starttextbackground[mtcframed]},
right={stoptextbackground},
space=collapse]

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text]

starttext

Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been mtc{the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book. It has survived
not only five centuries}, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.

stoptext


enter image description here






share|improve this answer


























  • +1: Great answer. LaTeX (and the contributors here) keep to amaze me.

    – Dr. Manuel Kuehner
    Dec 5 '18 at 22:55











  • Why use type? Isn't it better to simply set style=mono

    – Aditya
    Dec 6 '18 at 3:00











  • @Aditya In this case yes, but OP wants to use this to typeset code.

    – Henri Menke
    Dec 6 '18 at 3:09
















9














start...stoptextbackground is the correct thing to do but you have to set location=text. To collapse interword spaces, I define a new spacing method collapse and use it in setuptype. I also add a little bit of stretch and shrink to the interword space for better linebreaking.



% The original version, which only collapses interword spaces.
%unprotect
%defineinterfacevariable{collapse}{collapse}
%setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
%protect

% The updated version, which in addition adds stretch and shrink
unprotect
defineinterfacevariable{collapse}{collapse}
setvalue
{??typingspacev!collapse}%
{defobeyedspace{unskip
hskipinterwordspace
plus .5interwordspace
minus .5interwordspacerelax}}
protect

definetype
[mtc]
[left={starttextbackground[mtcframed]},
right={stoptextbackground},
space=collapse]

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text]

starttext

Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been mtc{the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book. It has survived
not only five centuries}, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.

stoptext


enter image description here






share|improve this answer


























  • +1: Great answer. LaTeX (and the contributors here) keep to amaze me.

    – Dr. Manuel Kuehner
    Dec 5 '18 at 22:55











  • Why use type? Isn't it better to simply set style=mono

    – Aditya
    Dec 6 '18 at 3:00











  • @Aditya In this case yes, but OP wants to use this to typeset code.

    – Henri Menke
    Dec 6 '18 at 3:09














9












9








9







start...stoptextbackground is the correct thing to do but you have to set location=text. To collapse interword spaces, I define a new spacing method collapse and use it in setuptype. I also add a little bit of stretch and shrink to the interword space for better linebreaking.



% The original version, which only collapses interword spaces.
%unprotect
%defineinterfacevariable{collapse}{collapse}
%setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
%protect

% The updated version, which in addition adds stretch and shrink
unprotect
defineinterfacevariable{collapse}{collapse}
setvalue
{??typingspacev!collapse}%
{defobeyedspace{unskip
hskipinterwordspace
plus .5interwordspace
minus .5interwordspacerelax}}
protect

definetype
[mtc]
[left={starttextbackground[mtcframed]},
right={stoptextbackground},
space=collapse]

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text]

starttext

Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been mtc{the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book. It has survived
not only five centuries}, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.

stoptext


enter image description here






share|improve this answer















start...stoptextbackground is the correct thing to do but you have to set location=text. To collapse interword spaces, I define a new spacing method collapse and use it in setuptype. I also add a little bit of stretch and shrink to the interword space for better linebreaking.



% The original version, which only collapses interword spaces.
%unprotect
%defineinterfacevariable{collapse}{collapse}
%setvalue{??typingspacev!collapse}{defobeyedspace{unskipspace}}
%protect

% The updated version, which in addition adds stretch and shrink
unprotect
defineinterfacevariable{collapse}{collapse}
setvalue
{??typingspacev!collapse}%
{defobeyedspace{unskip
hskipinterwordspace
plus .5interwordspace
minus .5interwordspacerelax}}
protect

definetype
[mtc]
[left={starttextbackground[mtcframed]},
right={stoptextbackground},
space=collapse]

definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text]

starttext

Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been mtc{the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book. It has survived
not only five centuries}, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.

stoptext


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 5 '18 at 22:44









user19087

3368




3368










answered Dec 1 '18 at 4:02









Henri MenkeHenri Menke

71.4k8158266




71.4k8158266













  • +1: Great answer. LaTeX (and the contributors here) keep to amaze me.

    – Dr. Manuel Kuehner
    Dec 5 '18 at 22:55











  • Why use type? Isn't it better to simply set style=mono

    – Aditya
    Dec 6 '18 at 3:00











  • @Aditya In this case yes, but OP wants to use this to typeset code.

    – Henri Menke
    Dec 6 '18 at 3:09



















  • +1: Great answer. LaTeX (and the contributors here) keep to amaze me.

    – Dr. Manuel Kuehner
    Dec 5 '18 at 22:55











  • Why use type? Isn't it better to simply set style=mono

    – Aditya
    Dec 6 '18 at 3:00











  • @Aditya In this case yes, but OP wants to use this to typeset code.

    – Henri Menke
    Dec 6 '18 at 3:09

















+1: Great answer. LaTeX (and the contributors here) keep to amaze me.

– Dr. Manuel Kuehner
Dec 5 '18 at 22:55





+1: Great answer. LaTeX (and the contributors here) keep to amaze me.

– Dr. Manuel Kuehner
Dec 5 '18 at 22:55













Why use type? Isn't it better to simply set style=mono

– Aditya
Dec 6 '18 at 3:00





Why use type? Isn't it better to simply set style=mono

– Aditya
Dec 6 '18 at 3:00













@Aditya In this case yes, but OP wants to use this to typeset code.

– Henri Menke
Dec 6 '18 at 3:09





@Aditya In this case yes, but OP wants to use this to typeset code.

– Henri Menke
Dec 6 '18 at 3:09


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462652%2fcontext-frame-a-sentence%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

Puebla de Zaragoza

Musa