Typesetting a comma unless before a line breakAutomatic break line after multicolumnLine break (continuation) for commands (options, arguments)Derivatives conditional typesetting command?Line break after command, before periodrenewcommand with comma-separated argumentsUsing phantom labels to hold complex and dynamically defined macrospoint to comma macroLine break in macro with > 9 parametersColor until line break (without luatex)
Are language and thought the same?
Why do many programmers abstain from using global variables?
std::tuple sizeof, is it a missed optimization?
Deleting millions of records on SQL Server 14.0
Too many SOQL Queries when inserting records
Does this bike use hydraulic brakes?
Powering an offset stacked array of pistons
What does "se jouer" mean here?
What happens if I double Meddling Mage's 'enter the battlefield' trigger?
Tiny image scraper for xkcd.com
Is it rude to ask my opponent to resign an online game when they have a lost endgame?
Does immunity to damage from nonmagical attacks negate a rogue's Sneak Attack damage?
How can I oppose my advisor granting gift authorship to a collaborator?
Count rook moves 1D
Do I need to get a noble in order to win Splendor?
What is this red bug infesting some trees in southern Germany?
In-universe, why does Doc Brown program the time machine to go to 1955?
Case Studies and Real Problems for Teaching Optimization and Modelling
What's the difference between a share and a stock?
How could it be that the capo isn't changing the pitch?
When making yogurt, why doesn't bad bacteria grow as well?
The little bee buzzes around the flower garden
Why did the Joi advertisement trigger K?
What happens when there is no available physical memory left for SQL Server?
Typesetting a comma unless before a line break
Automatic break line after multicolumnLine break (continuation) for commands (options, arguments)Derivatives conditional typesetting command?Line break after command, before periodrenewcommand with comma-separated argumentsUsing phantom labels to hold complex and dynamically defined macrospoint to comma macroLine break in macro with > 9 parametersColor until line break (without luatex)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to create a template (.sty file) that will typeset
[value of macro 1], [value of macro 2]
if this expression does not exceed the length of the line, and
[value of macro 1]
[value of macro 2]
otherwise in a centered environment. My first idea was using mbox to prevent linebreaks within the fields themselves, but that leaves me with the problem of figuring out how to make LaTeX ignore the comma if the line break occurs. I then tried to solve the problem using
newcommand@macroambox[value of macro1]
newcommand@macrobmbox[value of macro2]
newcommand@macrocmbox[value of macro1], [value of macro2]
discretionary@macroa@macrob@macroc
which kind of does what I want, but with a major caveat - if a linebreak occurs, the text isn't centered anymore, but now gets typeset as
| [value of macro1]|
|[value of macro 2] |
and I can't figure out how to insert the proper glue without causing LaTeX to raise an Improper discretionary list. error...
Ouch, I have figured out my mistake - I wasn't in a centered environment after all, but using hfils. Changing to centering solved the problem for me. Guess I should revisit the source code once more next time before writing up a question... however, I think I'm just gonna leave this here, since Google didn't come up with useful results for this use case, so maybe it'll be useful to someone else one day. My apologies!
macros package-writing discretionary
add a comment |
I'm trying to create a template (.sty file) that will typeset
[value of macro 1], [value of macro 2]
if this expression does not exceed the length of the line, and
[value of macro 1]
[value of macro 2]
otherwise in a centered environment. My first idea was using mbox to prevent linebreaks within the fields themselves, but that leaves me with the problem of figuring out how to make LaTeX ignore the comma if the line break occurs. I then tried to solve the problem using
newcommand@macroambox[value of macro1]
newcommand@macrobmbox[value of macro2]
newcommand@macrocmbox[value of macro1], [value of macro2]
discretionary@macroa@macrob@macroc
which kind of does what I want, but with a major caveat - if a linebreak occurs, the text isn't centered anymore, but now gets typeset as
| [value of macro1]|
|[value of macro 2] |
and I can't figure out how to insert the proper glue without causing LaTeX to raise an Improper discretionary list. error...
Ouch, I have figured out my mistake - I wasn't in a centered environment after all, but using hfils. Changing to centering solved the problem for me. Guess I should revisit the source code once more next time before writing up a question... however, I think I'm just gonna leave this here, since Google didn't come up with useful results for this use case, so maybe it'll be useful to someone else one day. My apologies!
macros package-writing discretionary
2
It works for me if I replace@macro1(which is invalid) by@macroa, and the same for the other two.
– Phelype Oleinik
9 hours ago
@PhelypeOleinik I'm sorry, I inserted these numbers into the example by mistake. My.styfile uses macro names without numbers... my problem is with the alignment, as stated in the question.
– Sora.
8 hours ago
add a comment |
I'm trying to create a template (.sty file) that will typeset
[value of macro 1], [value of macro 2]
if this expression does not exceed the length of the line, and
[value of macro 1]
[value of macro 2]
otherwise in a centered environment. My first idea was using mbox to prevent linebreaks within the fields themselves, but that leaves me with the problem of figuring out how to make LaTeX ignore the comma if the line break occurs. I then tried to solve the problem using
newcommand@macroambox[value of macro1]
newcommand@macrobmbox[value of macro2]
newcommand@macrocmbox[value of macro1], [value of macro2]
discretionary@macroa@macrob@macroc
which kind of does what I want, but with a major caveat - if a linebreak occurs, the text isn't centered anymore, but now gets typeset as
| [value of macro1]|
|[value of macro 2] |
and I can't figure out how to insert the proper glue without causing LaTeX to raise an Improper discretionary list. error...
Ouch, I have figured out my mistake - I wasn't in a centered environment after all, but using hfils. Changing to centering solved the problem for me. Guess I should revisit the source code once more next time before writing up a question... however, I think I'm just gonna leave this here, since Google didn't come up with useful results for this use case, so maybe it'll be useful to someone else one day. My apologies!
macros package-writing discretionary
I'm trying to create a template (.sty file) that will typeset
[value of macro 1], [value of macro 2]
if this expression does not exceed the length of the line, and
[value of macro 1]
[value of macro 2]
otherwise in a centered environment. My first idea was using mbox to prevent linebreaks within the fields themselves, but that leaves me with the problem of figuring out how to make LaTeX ignore the comma if the line break occurs. I then tried to solve the problem using
newcommand@macroambox[value of macro1]
newcommand@macrobmbox[value of macro2]
newcommand@macrocmbox[value of macro1], [value of macro2]
discretionary@macroa@macrob@macroc
which kind of does what I want, but with a major caveat - if a linebreak occurs, the text isn't centered anymore, but now gets typeset as
| [value of macro1]|
|[value of macro 2] |
and I can't figure out how to insert the proper glue without causing LaTeX to raise an Improper discretionary list. error...
Ouch, I have figured out my mistake - I wasn't in a centered environment after all, but using hfils. Changing to centering solved the problem for me. Guess I should revisit the source code once more next time before writing up a question... however, I think I'm just gonna leave this here, since Google didn't come up with useful results for this use case, so maybe it'll be useful to someone else one day. My apologies!
macros package-writing discretionary
macros package-writing discretionary
edited 8 hours ago
Sora.
asked 9 hours ago
Sora.Sora.
3231 silver badge9 bronze badges
3231 silver badge9 bronze badges
2
It works for me if I replace@macro1(which is invalid) by@macroa, and the same for the other two.
– Phelype Oleinik
9 hours ago
@PhelypeOleinik I'm sorry, I inserted these numbers into the example by mistake. My.styfile uses macro names without numbers... my problem is with the alignment, as stated in the question.
– Sora.
8 hours ago
add a comment |
2
It works for me if I replace@macro1(which is invalid) by@macroa, and the same for the other two.
– Phelype Oleinik
9 hours ago
@PhelypeOleinik I'm sorry, I inserted these numbers into the example by mistake. My.styfile uses macro names without numbers... my problem is with the alignment, as stated in the question.
– Sora.
8 hours ago
2
2
It works for me if I replace
@macro1 (which is invalid) by @macroa, and the same for the other two.– Phelype Oleinik
9 hours ago
It works for me if I replace
@macro1 (which is invalid) by @macroa, and the same for the other two.– Phelype Oleinik
9 hours ago
@PhelypeOleinik I'm sorry, I inserted these numbers into the example by mistake. My
.sty file uses macro names without numbers... my problem is with the alignment, as stated in the question.– Sora.
8 hours ago
@PhelypeOleinik I'm sorry, I inserted these numbers into the example by mistake. My
.sty file uses macro names without numbers... my problem is with the alignment, as stated in the question.– Sora.
8 hours ago
add a comment |
2 Answers
2
active
oldest
votes
You can typeset the comma as if it were glue (using xleaders); since glue disappears at line breaks, also the comma will.
documentclassarticle
newcommanddisappearingcomma%
leavevmode
sbox0,%
xleaderscopy0hskipwd0relax
space
newcommandmacroaValue of macro A
newcommandmacrobValue of macro B
newcommandmacroabmboxmacroadisappearingcommamboxmacrob
begindocument
beginminipage6cm
centering
macroab
endminipagevrule
beginminipage4cm
centering
macroab
endminipage
enddocument

add a comment |
As @PhelypeOleinik has already pointed out in a comment, the macro names @macro1, @macro2, and @macro3 are invalid -- the digits 0 thru 9 are not allowed in multiple-character TeX and LaTeX macro names. I therefore suggest you use @macroa, @macrob, and @macroc instead.

documentclassarticle
usepackage[utf8]inputenc %
makeatletter
newcommand@macroambox[value of macro A]
newcommand@macrobmbox[value of macro B]
newcommand@macrocmbox[value of macro A], [value of macro B]
newcommandblurbdiscretionary@macroa@macrob@macroc
%% Or, far more succinctly, David Carlisle's excellent suggestion:
%% newcommandblurb@macroadiscretionaryhbox, @macrob
%% With this approach, it's not necessary to define '@macroc'.
makeatother
setlengthparindent0pt
%setlengthtextwidth1mm % uncomment to get a very narrow measure
begindocument
blurb
enddocument
4
why not@macroadiscretionaryhbox, @macrob?
– David Carlisle
8 hours ago
@DavidCarlisle - An excellent suggestion! :-) I've edited my answer to add some comments to mention this much simpler solution.
– Mico
8 hours ago
@DavidCarlisle thanks, good idea!
– Sora.
8 hours ago
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%2f506826%2ftypesetting-a-comma-unless-before-a-line-break%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can typeset the comma as if it were glue (using xleaders); since glue disappears at line breaks, also the comma will.
documentclassarticle
newcommanddisappearingcomma%
leavevmode
sbox0,%
xleaderscopy0hskipwd0relax
space
newcommandmacroaValue of macro A
newcommandmacrobValue of macro B
newcommandmacroabmboxmacroadisappearingcommamboxmacrob
begindocument
beginminipage6cm
centering
macroab
endminipagevrule
beginminipage4cm
centering
macroab
endminipage
enddocument

add a comment |
You can typeset the comma as if it were glue (using xleaders); since glue disappears at line breaks, also the comma will.
documentclassarticle
newcommanddisappearingcomma%
leavevmode
sbox0,%
xleaderscopy0hskipwd0relax
space
newcommandmacroaValue of macro A
newcommandmacrobValue of macro B
newcommandmacroabmboxmacroadisappearingcommamboxmacrob
begindocument
beginminipage6cm
centering
macroab
endminipagevrule
beginminipage4cm
centering
macroab
endminipage
enddocument

add a comment |
You can typeset the comma as if it were glue (using xleaders); since glue disappears at line breaks, also the comma will.
documentclassarticle
newcommanddisappearingcomma%
leavevmode
sbox0,%
xleaderscopy0hskipwd0relax
space
newcommandmacroaValue of macro A
newcommandmacrobValue of macro B
newcommandmacroabmboxmacroadisappearingcommamboxmacrob
begindocument
beginminipage6cm
centering
macroab
endminipagevrule
beginminipage4cm
centering
macroab
endminipage
enddocument

You can typeset the comma as if it were glue (using xleaders); since glue disappears at line breaks, also the comma will.
documentclassarticle
newcommanddisappearingcomma%
leavevmode
sbox0,%
xleaderscopy0hskipwd0relax
space
newcommandmacroaValue of macro A
newcommandmacrobValue of macro B
newcommandmacroabmboxmacroadisappearingcommamboxmacrob
begindocument
beginminipage6cm
centering
macroab
endminipagevrule
beginminipage4cm
centering
macroab
endminipage
enddocument

answered 4 hours ago
egregegreg
766k90 gold badges2000 silver badges3352 bronze badges
766k90 gold badges2000 silver badges3352 bronze badges
add a comment |
add a comment |
As @PhelypeOleinik has already pointed out in a comment, the macro names @macro1, @macro2, and @macro3 are invalid -- the digits 0 thru 9 are not allowed in multiple-character TeX and LaTeX macro names. I therefore suggest you use @macroa, @macrob, and @macroc instead.

documentclassarticle
usepackage[utf8]inputenc %
makeatletter
newcommand@macroambox[value of macro A]
newcommand@macrobmbox[value of macro B]
newcommand@macrocmbox[value of macro A], [value of macro B]
newcommandblurbdiscretionary@macroa@macrob@macroc
%% Or, far more succinctly, David Carlisle's excellent suggestion:
%% newcommandblurb@macroadiscretionaryhbox, @macrob
%% With this approach, it's not necessary to define '@macroc'.
makeatother
setlengthparindent0pt
%setlengthtextwidth1mm % uncomment to get a very narrow measure
begindocument
blurb
enddocument
4
why not@macroadiscretionaryhbox, @macrob?
– David Carlisle
8 hours ago
@DavidCarlisle - An excellent suggestion! :-) I've edited my answer to add some comments to mention this much simpler solution.
– Mico
8 hours ago
@DavidCarlisle thanks, good idea!
– Sora.
8 hours ago
add a comment |
As @PhelypeOleinik has already pointed out in a comment, the macro names @macro1, @macro2, and @macro3 are invalid -- the digits 0 thru 9 are not allowed in multiple-character TeX and LaTeX macro names. I therefore suggest you use @macroa, @macrob, and @macroc instead.

documentclassarticle
usepackage[utf8]inputenc %
makeatletter
newcommand@macroambox[value of macro A]
newcommand@macrobmbox[value of macro B]
newcommand@macrocmbox[value of macro A], [value of macro B]
newcommandblurbdiscretionary@macroa@macrob@macroc
%% Or, far more succinctly, David Carlisle's excellent suggestion:
%% newcommandblurb@macroadiscretionaryhbox, @macrob
%% With this approach, it's not necessary to define '@macroc'.
makeatother
setlengthparindent0pt
%setlengthtextwidth1mm % uncomment to get a very narrow measure
begindocument
blurb
enddocument
4
why not@macroadiscretionaryhbox, @macrob?
– David Carlisle
8 hours ago
@DavidCarlisle - An excellent suggestion! :-) I've edited my answer to add some comments to mention this much simpler solution.
– Mico
8 hours ago
@DavidCarlisle thanks, good idea!
– Sora.
8 hours ago
add a comment |
As @PhelypeOleinik has already pointed out in a comment, the macro names @macro1, @macro2, and @macro3 are invalid -- the digits 0 thru 9 are not allowed in multiple-character TeX and LaTeX macro names. I therefore suggest you use @macroa, @macrob, and @macroc instead.

documentclassarticle
usepackage[utf8]inputenc %
makeatletter
newcommand@macroambox[value of macro A]
newcommand@macrobmbox[value of macro B]
newcommand@macrocmbox[value of macro A], [value of macro B]
newcommandblurbdiscretionary@macroa@macrob@macroc
%% Or, far more succinctly, David Carlisle's excellent suggestion:
%% newcommandblurb@macroadiscretionaryhbox, @macrob
%% With this approach, it's not necessary to define '@macroc'.
makeatother
setlengthparindent0pt
%setlengthtextwidth1mm % uncomment to get a very narrow measure
begindocument
blurb
enddocument
As @PhelypeOleinik has already pointed out in a comment, the macro names @macro1, @macro2, and @macro3 are invalid -- the digits 0 thru 9 are not allowed in multiple-character TeX and LaTeX macro names. I therefore suggest you use @macroa, @macrob, and @macroc instead.

documentclassarticle
usepackage[utf8]inputenc %
makeatletter
newcommand@macroambox[value of macro A]
newcommand@macrobmbox[value of macro B]
newcommand@macrocmbox[value of macro A], [value of macro B]
newcommandblurbdiscretionary@macroa@macrob@macroc
%% Or, far more succinctly, David Carlisle's excellent suggestion:
%% newcommandblurb@macroadiscretionaryhbox, @macrob
%% With this approach, it's not necessary to define '@macroc'.
makeatother
setlengthparindent0pt
%setlengthtextwidth1mm % uncomment to get a very narrow measure
begindocument
blurb
enddocument
edited 8 hours ago
answered 8 hours ago
MicoMico
304k33 gold badges418 silver badges828 bronze badges
304k33 gold badges418 silver badges828 bronze badges
4
why not@macroadiscretionaryhbox, @macrob?
– David Carlisle
8 hours ago
@DavidCarlisle - An excellent suggestion! :-) I've edited my answer to add some comments to mention this much simpler solution.
– Mico
8 hours ago
@DavidCarlisle thanks, good idea!
– Sora.
8 hours ago
add a comment |
4
why not@macroadiscretionaryhbox, @macrob?
– David Carlisle
8 hours ago
@DavidCarlisle - An excellent suggestion! :-) I've edited my answer to add some comments to mention this much simpler solution.
– Mico
8 hours ago
@DavidCarlisle thanks, good idea!
– Sora.
8 hours ago
4
4
why not
@macroadiscretionaryhbox, @macrob ?– David Carlisle
8 hours ago
why not
@macroadiscretionaryhbox, @macrob ?– David Carlisle
8 hours ago
@DavidCarlisle - An excellent suggestion! :-) I've edited my answer to add some comments to mention this much simpler solution.
– Mico
8 hours ago
@DavidCarlisle - An excellent suggestion! :-) I've edited my answer to add some comments to mention this much simpler solution.
– Mico
8 hours ago
@DavidCarlisle thanks, good idea!
– Sora.
8 hours ago
@DavidCarlisle thanks, good idea!
– Sora.
8 hours ago
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.
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%2f506826%2ftypesetting-a-comma-unless-before-a-line-break%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
2
It works for me if I replace
@macro1(which is invalid) by@macroa, and the same for the other two.– Phelype Oleinik
9 hours ago
@PhelypeOleinik I'm sorry, I inserted these numbers into the example by mistake. My
.styfile uses macro names without numbers... my problem is with the alignment, as stated in the question.– Sora.
8 hours ago