ConTeXt: Frame a Sentence
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 unlikecolor
doesn't ignore input whitespace.
start...stoptextbackground
forces a new block even when used asleft=
andright=
arguments tosetuptype
.
framed
doesn't actually wrap the input totype
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
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
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},
]
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
|
show 8 more comments
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 unlikecolor
doesn't ignore input whitespace.
start...stoptextbackground
forces a new block even when used asleft=
andright=
arguments tosetuptype
.
framed
doesn't actually wrap the input totype
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
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
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},
]
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
Usedefinetype[mtc][space=stretch]
to get the regular interword glue. I have also updated my answer.
– Henri Menke
Dec 1 at 6:44
For me it doesn't spill out the frame. Are you using the latest beta?
– Henri Menke
Dec 2 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 at 8:00
Hyphenation is disabled fortype
, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph usingtt
I actually have more hyphenation than without. As fortype
settinglines=hyphenated
doesn't influence the overflow.
– user19087
Dec 2 at 15:34
I'm using the ConTeXt standalone beta 2018.10.18.
– user19087
Dec 2 at 15:34
|
show 8 more comments
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 unlikecolor
doesn't ignore input whitespace.
start...stoptextbackground
forces a new block even when used asleft=
andright=
arguments tosetuptype
.
framed
doesn't actually wrap the input totype
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
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
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},
]
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
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 unlikecolor
doesn't ignore input whitespace.
start...stoptextbackground
forces a new block even when used asleft=
andright=
arguments tosetuptype
.
framed
doesn't actually wrap the input totype
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
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
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},
]
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
formatting context backgrounds
edited Dec 2 at 7:25
asked Dec 1 at 3:27
user19087
2676
2676
Usedefinetype[mtc][space=stretch]
to get the regular interword glue. I have also updated my answer.
– Henri Menke
Dec 1 at 6:44
For me it doesn't spill out the frame. Are you using the latest beta?
– Henri Menke
Dec 2 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 at 8:00
Hyphenation is disabled fortype
, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph usingtt
I actually have more hyphenation than without. As fortype
settinglines=hyphenated
doesn't influence the overflow.
– user19087
Dec 2 at 15:34
I'm using the ConTeXt standalone beta 2018.10.18.
– user19087
Dec 2 at 15:34
|
show 8 more comments
Usedefinetype[mtc][space=stretch]
to get the regular interword glue. I have also updated my answer.
– Henri Menke
Dec 1 at 6:44
For me it doesn't spill out the frame. Are you using the latest beta?
– Henri Menke
Dec 2 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 at 8:00
Hyphenation is disabled fortype
, but it doesn't seem by default switched off for teletype fonts. If I typeset my example paragraph usingtt
I actually have more hyphenation than without. As fortype
settinglines=hyphenated
doesn't influence the overflow.
– user19087
Dec 2 at 15:34
I'm using the ConTeXt standalone beta 2018.10.18.
– user19087
Dec 2 at 15:34
Use
definetype[mtc][space=stretch]
to get the regular interword glue. I have also updated my answer.– Henri Menke
Dec 1 at 6:44
Use
definetype[mtc][space=stretch]
to get the regular interword glue. I have also updated my answer.– Henri Menke
Dec 1 at 6:44
For me it doesn't spill out the frame. Are you using the latest beta?
– Henri Menke
Dec 2 at 7:58
For me it doesn't spill out the frame. Are you using the latest beta?
– Henri Menke
Dec 2 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 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 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 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 at 15:34
I'm using the ConTeXt standalone beta 2018.10.18.
– user19087
Dec 2 at 15:34
I'm using the ConTeXt standalone beta 2018.10.18.
– user19087
Dec 2 at 15:34
|
show 8 more comments
1 Answer
1
active
oldest
votes
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
+1: Great answer. LaTeX (and the contributors here) keep to amaze me.
– Dr. Manuel Kuehner
Dec 5 at 22:55
Why usetype
? Isn't it better to simply setstyle=mono
– Aditya
Dec 6 at 3:00
@Aditya In this case yes, but OP wants to use this to typeset code.
– Henri Menke
Dec 6 at 3:09
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
+1: Great answer. LaTeX (and the contributors here) keep to amaze me.
– Dr. Manuel Kuehner
Dec 5 at 22:55
Why usetype
? Isn't it better to simply setstyle=mono
– Aditya
Dec 6 at 3:00
@Aditya In this case yes, but OP wants to use this to typeset code.
– Henri Menke
Dec 6 at 3:09
add a comment |
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
+1: Great answer. LaTeX (and the contributors here) keep to amaze me.
– Dr. Manuel Kuehner
Dec 5 at 22:55
Why usetype
? Isn't it better to simply setstyle=mono
– Aditya
Dec 6 at 3:00
@Aditya In this case yes, but OP wants to use this to typeset code.
– Henri Menke
Dec 6 at 3:09
add a comment |
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
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
edited Dec 5 at 22:44
user19087
2676
2676
answered Dec 1 at 4:02
Henri Menke
69.4k8155258
69.4k8155258
+1: Great answer. LaTeX (and the contributors here) keep to amaze me.
– Dr. Manuel Kuehner
Dec 5 at 22:55
Why usetype
? Isn't it better to simply setstyle=mono
– Aditya
Dec 6 at 3:00
@Aditya In this case yes, but OP wants to use this to typeset code.
– Henri Menke
Dec 6 at 3:09
add a comment |
+1: Great answer. LaTeX (and the contributors here) keep to amaze me.
– Dr. Manuel Kuehner
Dec 5 at 22:55
Why usetype
? Isn't it better to simply setstyle=mono
– Aditya
Dec 6 at 3:00
@Aditya In this case yes, but OP wants to use this to typeset code.
– Henri Menke
Dec 6 at 3:09
+1: Great answer. LaTeX (and the contributors here) keep to amaze me.
– Dr. Manuel Kuehner
Dec 5 at 22:55
+1: Great answer. LaTeX (and the contributors here) keep to amaze me.
– Dr. Manuel Kuehner
Dec 5 at 22:55
Why use
type
? Isn't it better to simply set style=mono
– Aditya
Dec 6 at 3:00
Why use
type
? Isn't it better to simply set style=mono
– Aditya
Dec 6 at 3:00
@Aditya In this case yes, but OP wants to use this to typeset code.
– Henri Menke
Dec 6 at 3:09
@Aditya In this case yes, but OP wants to use this to typeset code.
– Henri Menke
Dec 6 at 3:09
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Use
definetype[mtc][space=stretch]
to get the regular interword glue. I have also updated my answer.– Henri Menke
Dec 1 at 6:44
For me it doesn't spill out the frame. Are you using the latest beta?
– Henri Menke
Dec 2 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 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 usingtt
I actually have more hyphenation than without. As fortype
settinglines=hyphenated
doesn't influence the overflow.– user19087
Dec 2 at 15:34
I'm using the ConTeXt standalone beta 2018.10.18.
– user19087
Dec 2 at 15:34