How is it possible to use square brackets as shorthand commands?How to use CheckCommand with robust commands?Labelling commands for quick useone and the same command for different outputs depending on position in documentHow call several commands by one commands?Can't use command with square brackets in matrix environmentSquare brackets [ ] as first text inside environmentIs it possible to automatically replace commands shortcuts with the corresponding TeX commands?Can't use macro in square bracketsDisplay square brackets in the output macro definitionShould I use ` ` or `` after custom commands?
Through the Looking-Glass
What sort of mathematical problems are there in AI that people are working on?
Did Karl Marx ever use any example that involved cotton and dollars to illustrate the way capital and surplus value were generated?
How to perform Login Authentication at the client-side?
Why is the voltage measurement of this circuit different when the switch is on?
Should my manager be aware of private LinkedIn approaches I receive? How to politely have this happen?
Using “sparkling” as a diminutive of “spark” in a poem
How to split an equation over two lines?
How can I deal with a coworker killed on the job
Does squid ink pasta bleed?
Why is Madam Hooch not a professor?
Require advice on power conservation for backpacking trip
Change the boot order with no option in UEFI settings
Alphabet completion rate
Does the posterior necessarily follow the same conditional dependence structure as the prior?
Is this one of the engines from the 9/11 aircraft?
Why do textbooks often include the solutions to odd or even numbered problems but not both?
Going to get married soon, should I do it on Dec 31 or Jan 1?
Links to webpages in books
Swapping rooks in a 4x4 board
Is it damaging to turn off a small fridge for two days every week?
Change CPU MHz from Registry
What are the penalties for overstaying in USA?
How dangerous are set-size assumptions?
How is it possible to use square brackets as shorthand commands?
How to use CheckCommand with robust commands?Labelling commands for quick useone and the same command for different outputs depending on position in documentHow call several commands by one commands?Can't use command with square brackets in matrix environmentSquare brackets [ ] as first text inside environmentIs it possible to automatically replace commands shortcuts with the corresponding TeX commands?Can't use macro in square bracketsDisplay square brackets in the output macro definitionShould I use ` ` or `` after custom commands?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have defined a command, that is used in text scripts for stageplays.
At the moment, you can write:
says[quietly]MinkaHello, are you there?
which compiles to something like:
*Minka*: (quietly) Hello, are you there?
where Minka
is bold and quietly
is slanted and colored.
however, I was asked, if i could provide "multiple square brackets" as they wanted to write:
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
which should compile to:
*Minka*: (quieltly) Hello, are you there? (shouting) Is anyone there?
My question is, can I somehow parse the text that is given to saysnametext
and replace all parts between square brackets with some command?
EDIT: Current Says Command:
newlengthwidest
settowidthwidesttextbfLongest Name in document
newcommandsays[2]
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]
item[#1] #2
enddescription
where the #2
should be the part on the right. I also redefine the command at the beginning of the script:
newcommandminka[1]saysMinka#1
newcommandarthur[1]saysArthur#1
and probably use more than one line or paragraph of text:
minkaHello, you//
[louder] yes, you there!
[normal voice] Is it you that helped me with that latex stuff?
macros
add a comment |
I have defined a command, that is used in text scripts for stageplays.
At the moment, you can write:
says[quietly]MinkaHello, are you there?
which compiles to something like:
*Minka*: (quietly) Hello, are you there?
where Minka
is bold and quietly
is slanted and colored.
however, I was asked, if i could provide "multiple square brackets" as they wanted to write:
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
which should compile to:
*Minka*: (quieltly) Hello, are you there? (shouting) Is anyone there?
My question is, can I somehow parse the text that is given to saysnametext
and replace all parts between square brackets with some command?
EDIT: Current Says Command:
newlengthwidest
settowidthwidesttextbfLongest Name in document
newcommandsays[2]
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]
item[#1] #2
enddescription
where the #2
should be the part on the right. I also redefine the command at the beginning of the script:
newcommandminka[1]saysMinka#1
newcommandarthur[1]saysArthur#1
and probably use more than one line or paragraph of text:
minkaHello, you//
[louder] yes, you there!
[normal voice] Is it you that helped me with that latex stuff?
macros
It is possible, but an input syntax likesaysMinkahowquietly Hello, are you there? howshouting Is anyone there?
as @user605895 seems to be suggesting looks like cleaner markup to me.
– frougon
Jun 15 at 11:32
Yes, but sqare brackets arebway easier to explain to our users.
– Tobi
Jun 15 at 17:20
Okay, please see my answer below.
– frougon
Jun 15 at 19:01
add a comment |
I have defined a command, that is used in text scripts for stageplays.
At the moment, you can write:
says[quietly]MinkaHello, are you there?
which compiles to something like:
*Minka*: (quietly) Hello, are you there?
where Minka
is bold and quietly
is slanted and colored.
however, I was asked, if i could provide "multiple square brackets" as they wanted to write:
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
which should compile to:
*Minka*: (quieltly) Hello, are you there? (shouting) Is anyone there?
My question is, can I somehow parse the text that is given to saysnametext
and replace all parts between square brackets with some command?
EDIT: Current Says Command:
newlengthwidest
settowidthwidesttextbfLongest Name in document
newcommandsays[2]
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]
item[#1] #2
enddescription
where the #2
should be the part on the right. I also redefine the command at the beginning of the script:
newcommandminka[1]saysMinka#1
newcommandarthur[1]saysArthur#1
and probably use more than one line or paragraph of text:
minkaHello, you//
[louder] yes, you there!
[normal voice] Is it you that helped me with that latex stuff?
macros
I have defined a command, that is used in text scripts for stageplays.
At the moment, you can write:
says[quietly]MinkaHello, are you there?
which compiles to something like:
*Minka*: (quietly) Hello, are you there?
where Minka
is bold and quietly
is slanted and colored.
however, I was asked, if i could provide "multiple square brackets" as they wanted to write:
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
which should compile to:
*Minka*: (quieltly) Hello, are you there? (shouting) Is anyone there?
My question is, can I somehow parse the text that is given to saysnametext
and replace all parts between square brackets with some command?
EDIT: Current Says Command:
newlengthwidest
settowidthwidesttextbfLongest Name in document
newcommandsays[2]
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]
item[#1] #2
enddescription
where the #2
should be the part on the right. I also redefine the command at the beginning of the script:
newcommandminka[1]saysMinka#1
newcommandarthur[1]saysArthur#1
and probably use more than one line or paragraph of text:
minkaHello, you//
[louder] yes, you there!
[normal voice] Is it you that helped me with that latex stuff?
macros
macros
edited Jun 18 at 19:28
Tobi
asked Jun 15 at 10:37
TobiTobi
1667 bronze badges
1667 bronze badges
It is possible, but an input syntax likesaysMinkahowquietly Hello, are you there? howshouting Is anyone there?
as @user605895 seems to be suggesting looks like cleaner markup to me.
– frougon
Jun 15 at 11:32
Yes, but sqare brackets arebway easier to explain to our users.
– Tobi
Jun 15 at 17:20
Okay, please see my answer below.
– frougon
Jun 15 at 19:01
add a comment |
It is possible, but an input syntax likesaysMinkahowquietly Hello, are you there? howshouting Is anyone there?
as @user605895 seems to be suggesting looks like cleaner markup to me.
– frougon
Jun 15 at 11:32
Yes, but sqare brackets arebway easier to explain to our users.
– Tobi
Jun 15 at 17:20
Okay, please see my answer below.
– frougon
Jun 15 at 19:01
It is possible, but an input syntax like
saysMinkahowquietly Hello, are you there? howshouting Is anyone there?
as @user605895 seems to be suggesting looks like cleaner markup to me.– frougon
Jun 15 at 11:32
It is possible, but an input syntax like
saysMinkahowquietly Hello, are you there? howshouting Is anyone there?
as @user605895 seems to be suggesting looks like cleaner markup to me.– frougon
Jun 15 at 11:32
Yes, but sqare brackets arebway easier to explain to our users.
– Tobi
Jun 15 at 17:20
Yes, but sqare brackets arebway easier to explain to our users.
– Tobi
Jun 15 at 17:20
Okay, please see my answer below.
– frougon
Jun 15 at 19:01
Okay, please see my answer below.
– frougon
Jun 15 at 19:01
add a comment |
3 Answers
3
active
oldest
votes
What you asked for can be done with LaTeX3's regex
module:
documentclassarticle
usepackagexcolor
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_says:nn #1#2
tl_set:Nn l_tmpa_tl #2
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
textbf#1: nobreakspace tl_use:N l_tmpa_tl
par
NewDocumentCommand says m m
tobiscript_says:nn #1 #2
ExplSyntaxOff
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
enddocument
Regarding your edited question, you can use this. In case you are not interested in the old says
command anymore, just remove its definition, then rename newsays
to says
or whatever name you want for the new commmand.
documentclassarticle
usepackagexcolor
usepackageenumitem
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_format_howsays_in_text:n #1
tl_set:Nn l_tmpa_tl #1
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
tl_use:N l_tmpa_tl
cs_new_protected:Npn tobiscript_says:nn #1#2
textbf#1: nobreakspace tobiscript_format_howsays_in_text:n #2
par
% says command as requested in the original question
NewDocumentCommand says m +m
tobiscript_says:nn #1 #2
NewDocumentCommand formathowsaysintext +m
tobiscript_format_howsays_in_text:n #1
ExplSyntaxOff
newlengthwidest
settowidthwidesttextbfLongest Name in document
% newsays: command added to the question after the answer was provided
newcommandnewsays[2]%
begindescription[leftmargin=dimexprwidest+labelseprelax,
labelindent=0pt,labelwidth=widest]
item[#1] formathowsaysintextignorespaces #2unskip
enddescription%
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
newsaysRoger
[irritated]Oh, what sad times are these when passing ruffians can say ``ni''
at will to old ladies.
[sorry for interrupting the show] Stupid paragraph added only to show this
can be done. [again, really sorry!] Back to the text in one second.
There is a pestilence upon this land. Nothing is sacred. Even
those who arrange and design shrubberies are under considerable economic
stress at this period in history.
newsaysArthur
[showing sudden interest] Did you say ``shrubberies''?
enddocument
what do I need to do, in order to make it work as a subcommand for my already existingsays
command? (see edit), what do I need to do to make it work for multiple lines of text?
– Tobi
Jun 18 at 19:25
Please see my last edit.
– frougon
2 days ago
add a comment |
You could use a different macro to indicate 'how' someone is saying something, e.g. as follows:
documentclassarticle
usepackagexcolor
newcommandhow[1]
textittextcolorred(#1)
begindocument
howquietly Hello, are you there? howshouting Is anyone there?
enddocument
I know how to define macros. The question was about square brackets
– Tobi
Jun 15 at 17:22
add a comment |
If you really want this interface, you can parse through the text with TeX:
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@stop@stop%
longdefsays@parse#1[#2]%
#1%
ifx@stop#2else
how#2%
expandaftersays@parse
fi
longdefsays#1#2%
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
item[#1]%
says@parse #2[@stop]%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
letnormalbackslash@backslashchar
makeatother
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysTobi
[annoyed] Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
[rambling]
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
[resigned] But okay, I'll explain it to you again.
[lecturing] You just write textttnormalbackslash says, then a pair of braces containing the name of the person speakingdots
[pausing] Good, like that.
Now you open another pair of braces and put their dialogue in there.
Close the brace, and [happily] you're done.
enddocument
This has some downsides.
- The syntax is not very well suited to the use, I think. Whenever you input many paragraphs as an argument to a macro, stop and ask yourself if this really should be an environment
- More importantly, as a consequence of this, you can't use any macros that change
catcode
s inside of the text (likeverb
). In my example, I had to usetexttt
and@backslashchar
instead.
A better approach, in my opinion, would be the use of an environment and an active character. We do not want to make [
(or ]
) active, because that would break all optional arguments. If you are open to changing the syntax from [instruction]
to |instruction|
, we can do this quite nicely though.
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@speech#1%
item[#1]%
catcode`
newenvironmentdialogue%
letspeech@speech
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
=12
gdefverticalbar
catcode`
makeatother
begindocument
begindialogue
speechMinka
|quietly|Hello, are you there? |shouting| Is anyone there?
speechTobi
|annoyed| Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
|rambling|
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
|resigned| But okay, I'll explain it to you again.
|lecturing| In the verb|dialogue| environment, you just write verb|speech|, then a pair of braces containing the name of the person speakingdots
|pausing| Good, like that.
Now you just type on what they should say.
Close the brace, and |happily| you're done.
enddialogue
enddocument
I like your second solution.|
is as good for my users as[...]
and it seems way more stable. However thebegin
...end
might already be too complex. I'll check if I can define mysays
in a way that it could handle that internally (e.g.newcommandsays[2]begindialoguespeech#1#2enddialogue
... One reason for this is: the less the users need to write the more likely is it, that they will use latex (instead of Google Docs and mess up all the layout)
– Tobi
2 days ago
@Tobi While it is possible to define such a syntax, I want to strongly discourage you from taking that path. You would either have to do a lot of low level programming to account for all the ways your users might use slightly different syntax than you intended, or you would still have to accept allcatcodes
to be frozen, even if you adjust|
first. It is much better to just teach your users what an environment is.
– schtandard
2 days ago
@Tobi As a more general point, I do not believe the way to get people to use LaTeX is to require them to use as few syntactical constructs as possible, but rather to design a clear interface that reflects the semantics of the content that is to be typeset. That is the fundamental strength of LaTeX, after all. (LaTeX has already done most of the work for you, here, compared to its foundation TeX. If you provide the preamble, your users will only have to learn the rules for spaces and paragraphs and a select number of macros and environments, with a highly standardized syntax.)
– schtandard
2 days 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%2f495885%2fhow-is-it-possible-to-use-square-brackets-as-shorthand-commands%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
What you asked for can be done with LaTeX3's regex
module:
documentclassarticle
usepackagexcolor
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_says:nn #1#2
tl_set:Nn l_tmpa_tl #2
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
textbf#1: nobreakspace tl_use:N l_tmpa_tl
par
NewDocumentCommand says m m
tobiscript_says:nn #1 #2
ExplSyntaxOff
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
enddocument
Regarding your edited question, you can use this. In case you are not interested in the old says
command anymore, just remove its definition, then rename newsays
to says
or whatever name you want for the new commmand.
documentclassarticle
usepackagexcolor
usepackageenumitem
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_format_howsays_in_text:n #1
tl_set:Nn l_tmpa_tl #1
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
tl_use:N l_tmpa_tl
cs_new_protected:Npn tobiscript_says:nn #1#2
textbf#1: nobreakspace tobiscript_format_howsays_in_text:n #2
par
% says command as requested in the original question
NewDocumentCommand says m +m
tobiscript_says:nn #1 #2
NewDocumentCommand formathowsaysintext +m
tobiscript_format_howsays_in_text:n #1
ExplSyntaxOff
newlengthwidest
settowidthwidesttextbfLongest Name in document
% newsays: command added to the question after the answer was provided
newcommandnewsays[2]%
begindescription[leftmargin=dimexprwidest+labelseprelax,
labelindent=0pt,labelwidth=widest]
item[#1] formathowsaysintextignorespaces #2unskip
enddescription%
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
newsaysRoger
[irritated]Oh, what sad times are these when passing ruffians can say ``ni''
at will to old ladies.
[sorry for interrupting the show] Stupid paragraph added only to show this
can be done. [again, really sorry!] Back to the text in one second.
There is a pestilence upon this land. Nothing is sacred. Even
those who arrange and design shrubberies are under considerable economic
stress at this period in history.
newsaysArthur
[showing sudden interest] Did you say ``shrubberies''?
enddocument
what do I need to do, in order to make it work as a subcommand for my already existingsays
command? (see edit), what do I need to do to make it work for multiple lines of text?
– Tobi
Jun 18 at 19:25
Please see my last edit.
– frougon
2 days ago
add a comment |
What you asked for can be done with LaTeX3's regex
module:
documentclassarticle
usepackagexcolor
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_says:nn #1#2
tl_set:Nn l_tmpa_tl #2
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
textbf#1: nobreakspace tl_use:N l_tmpa_tl
par
NewDocumentCommand says m m
tobiscript_says:nn #1 #2
ExplSyntaxOff
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
enddocument
Regarding your edited question, you can use this. In case you are not interested in the old says
command anymore, just remove its definition, then rename newsays
to says
or whatever name you want for the new commmand.
documentclassarticle
usepackagexcolor
usepackageenumitem
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_format_howsays_in_text:n #1
tl_set:Nn l_tmpa_tl #1
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
tl_use:N l_tmpa_tl
cs_new_protected:Npn tobiscript_says:nn #1#2
textbf#1: nobreakspace tobiscript_format_howsays_in_text:n #2
par
% says command as requested in the original question
NewDocumentCommand says m +m
tobiscript_says:nn #1 #2
NewDocumentCommand formathowsaysintext +m
tobiscript_format_howsays_in_text:n #1
ExplSyntaxOff
newlengthwidest
settowidthwidesttextbfLongest Name in document
% newsays: command added to the question after the answer was provided
newcommandnewsays[2]%
begindescription[leftmargin=dimexprwidest+labelseprelax,
labelindent=0pt,labelwidth=widest]
item[#1] formathowsaysintextignorespaces #2unskip
enddescription%
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
newsaysRoger
[irritated]Oh, what sad times are these when passing ruffians can say ``ni''
at will to old ladies.
[sorry for interrupting the show] Stupid paragraph added only to show this
can be done. [again, really sorry!] Back to the text in one second.
There is a pestilence upon this land. Nothing is sacred. Even
those who arrange and design shrubberies are under considerable economic
stress at this period in history.
newsaysArthur
[showing sudden interest] Did you say ``shrubberies''?
enddocument
what do I need to do, in order to make it work as a subcommand for my already existingsays
command? (see edit), what do I need to do to make it work for multiple lines of text?
– Tobi
Jun 18 at 19:25
Please see my last edit.
– frougon
2 days ago
add a comment |
What you asked for can be done with LaTeX3's regex
module:
documentclassarticle
usepackagexcolor
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_says:nn #1#2
tl_set:Nn l_tmpa_tl #2
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
textbf#1: nobreakspace tl_use:N l_tmpa_tl
par
NewDocumentCommand says m m
tobiscript_says:nn #1 #2
ExplSyntaxOff
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
enddocument
Regarding your edited question, you can use this. In case you are not interested in the old says
command anymore, just remove its definition, then rename newsays
to says
or whatever name you want for the new commmand.
documentclassarticle
usepackagexcolor
usepackageenumitem
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_format_howsays_in_text:n #1
tl_set:Nn l_tmpa_tl #1
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
tl_use:N l_tmpa_tl
cs_new_protected:Npn tobiscript_says:nn #1#2
textbf#1: nobreakspace tobiscript_format_howsays_in_text:n #2
par
% says command as requested in the original question
NewDocumentCommand says m +m
tobiscript_says:nn #1 #2
NewDocumentCommand formathowsaysintext +m
tobiscript_format_howsays_in_text:n #1
ExplSyntaxOff
newlengthwidest
settowidthwidesttextbfLongest Name in document
% newsays: command added to the question after the answer was provided
newcommandnewsays[2]%
begindescription[leftmargin=dimexprwidest+labelseprelax,
labelindent=0pt,labelwidth=widest]
item[#1] formathowsaysintextignorespaces #2unskip
enddescription%
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
newsaysRoger
[irritated]Oh, what sad times are these when passing ruffians can say ``ni''
at will to old ladies.
[sorry for interrupting the show] Stupid paragraph added only to show this
can be done. [again, really sorry!] Back to the text in one second.
There is a pestilence upon this land. Nothing is sacred. Even
those who arrange and design shrubberies are under considerable economic
stress at this period in history.
newsaysArthur
[showing sudden interest] Did you say ``shrubberies''?
enddocument
What you asked for can be done with LaTeX3's regex
module:
documentclassarticle
usepackagexcolor
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_says:nn #1#2
tl_set:Nn l_tmpa_tl #2
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
textbf#1: nobreakspace tl_use:N l_tmpa_tl
par
NewDocumentCommand says m m
tobiscript_says:nn #1 #2
ExplSyntaxOff
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
enddocument
Regarding your edited question, you can use this. In case you are not interested in the old says
command anymore, just remove its definition, then rename newsays
to says
or whatever name you want for the new commmand.
documentclassarticle
usepackagexcolor
usepackageenumitem
usepackagexparse
definecolorsaysHowRGB37,29,118
ExplSyntaxOn
regex_const:Nn l__tobiscript_howsays_regex [ ([^]]+) ]
cs_new_protected:Npn tobiscript_format_howsays_in_text:n #1
tl_set:Nn l_tmpa_tl #1
regex_replace_all:NnN l__tobiscript_howsays_regex
chow cB 1 cE
l_tmpa_tl
tl_use:N l_tmpa_tl
cs_new_protected:Npn tobiscript_says:nn #1#2
textbf#1: nobreakspace tobiscript_format_howsays_in_text:n #2
par
% says command as requested in the original question
NewDocumentCommand says m +m
tobiscript_says:nn #1 #2
NewDocumentCommand formathowsaysintext +m
tobiscript_format_howsays_in_text:n #1
ExplSyntaxOff
newlengthwidest
settowidthwidesttextbfLongest Name in document
% newsays: command added to the question after the answer was provided
newcommandnewsays[2]%
begindescription[leftmargin=dimexprwidest+labelseprelax,
labelindent=0pt,labelwidth=widest]
item[#1] formathowsaysintextignorespaces #2unskip
enddescription%
% Define how to format the things inside brackets
newcommand*how[1]%
textcolorsaysHowtextsl(#1)%
~ignorespaces % replace following spaces with one nobreak space
setlengthparindent0pt
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysArthur[hesitating] Uh, maybe me?.. [now assured] Patsy!
Patsy's here!
newsaysRoger
[irritated]Oh, what sad times are these when passing ruffians can say ``ni''
at will to old ladies.
[sorry for interrupting the show] Stupid paragraph added only to show this
can be done. [again, really sorry!] Back to the text in one second.
There is a pestilence upon this land. Nothing is sacred. Even
those who arrange and design shrubberies are under considerable economic
stress at this period in history.
newsaysArthur
[showing sudden interest] Did you say ``shrubberies''?
enddocument
edited 2 days ago
answered Jun 15 at 19:00
frougonfrougon
3,6851 gold badge9 silver badges18 bronze badges
3,6851 gold badge9 silver badges18 bronze badges
what do I need to do, in order to make it work as a subcommand for my already existingsays
command? (see edit), what do I need to do to make it work for multiple lines of text?
– Tobi
Jun 18 at 19:25
Please see my last edit.
– frougon
2 days ago
add a comment |
what do I need to do, in order to make it work as a subcommand for my already existingsays
command? (see edit), what do I need to do to make it work for multiple lines of text?
– Tobi
Jun 18 at 19:25
Please see my last edit.
– frougon
2 days ago
what do I need to do, in order to make it work as a subcommand for my already existing
says
command? (see edit), what do I need to do to make it work for multiple lines of text?– Tobi
Jun 18 at 19:25
what do I need to do, in order to make it work as a subcommand for my already existing
says
command? (see edit), what do I need to do to make it work for multiple lines of text?– Tobi
Jun 18 at 19:25
Please see my last edit.
– frougon
2 days ago
Please see my last edit.
– frougon
2 days ago
add a comment |
You could use a different macro to indicate 'how' someone is saying something, e.g. as follows:
documentclassarticle
usepackagexcolor
newcommandhow[1]
textittextcolorred(#1)
begindocument
howquietly Hello, are you there? howshouting Is anyone there?
enddocument
I know how to define macros. The question was about square brackets
– Tobi
Jun 15 at 17:22
add a comment |
You could use a different macro to indicate 'how' someone is saying something, e.g. as follows:
documentclassarticle
usepackagexcolor
newcommandhow[1]
textittextcolorred(#1)
begindocument
howquietly Hello, are you there? howshouting Is anyone there?
enddocument
I know how to define macros. The question was about square brackets
– Tobi
Jun 15 at 17:22
add a comment |
You could use a different macro to indicate 'how' someone is saying something, e.g. as follows:
documentclassarticle
usepackagexcolor
newcommandhow[1]
textittextcolorred(#1)
begindocument
howquietly Hello, are you there? howshouting Is anyone there?
enddocument
You could use a different macro to indicate 'how' someone is saying something, e.g. as follows:
documentclassarticle
usepackagexcolor
newcommandhow[1]
textittextcolorred(#1)
begindocument
howquietly Hello, are you there? howshouting Is anyone there?
enddocument
answered Jun 15 at 11:27
user605895user605895
3964 bronze badges
3964 bronze badges
I know how to define macros. The question was about square brackets
– Tobi
Jun 15 at 17:22
add a comment |
I know how to define macros. The question was about square brackets
– Tobi
Jun 15 at 17:22
I know how to define macros. The question was about square brackets
– Tobi
Jun 15 at 17:22
I know how to define macros. The question was about square brackets
– Tobi
Jun 15 at 17:22
add a comment |
If you really want this interface, you can parse through the text with TeX:
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@stop@stop%
longdefsays@parse#1[#2]%
#1%
ifx@stop#2else
how#2%
expandaftersays@parse
fi
longdefsays#1#2%
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
item[#1]%
says@parse #2[@stop]%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
letnormalbackslash@backslashchar
makeatother
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysTobi
[annoyed] Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
[rambling]
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
[resigned] But okay, I'll explain it to you again.
[lecturing] You just write textttnormalbackslash says, then a pair of braces containing the name of the person speakingdots
[pausing] Good, like that.
Now you open another pair of braces and put their dialogue in there.
Close the brace, and [happily] you're done.
enddocument
This has some downsides.
- The syntax is not very well suited to the use, I think. Whenever you input many paragraphs as an argument to a macro, stop and ask yourself if this really should be an environment
- More importantly, as a consequence of this, you can't use any macros that change
catcode
s inside of the text (likeverb
). In my example, I had to usetexttt
and@backslashchar
instead.
A better approach, in my opinion, would be the use of an environment and an active character. We do not want to make [
(or ]
) active, because that would break all optional arguments. If you are open to changing the syntax from [instruction]
to |instruction|
, we can do this quite nicely though.
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@speech#1%
item[#1]%
catcode`
newenvironmentdialogue%
letspeech@speech
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
=12
gdefverticalbar
catcode`
makeatother
begindocument
begindialogue
speechMinka
|quietly|Hello, are you there? |shouting| Is anyone there?
speechTobi
|annoyed| Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
|rambling|
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
|resigned| But okay, I'll explain it to you again.
|lecturing| In the verb|dialogue| environment, you just write verb|speech|, then a pair of braces containing the name of the person speakingdots
|pausing| Good, like that.
Now you just type on what they should say.
Close the brace, and |happily| you're done.
enddialogue
enddocument
I like your second solution.|
is as good for my users as[...]
and it seems way more stable. However thebegin
...end
might already be too complex. I'll check if I can define mysays
in a way that it could handle that internally (e.g.newcommandsays[2]begindialoguespeech#1#2enddialogue
... One reason for this is: the less the users need to write the more likely is it, that they will use latex (instead of Google Docs and mess up all the layout)
– Tobi
2 days ago
@Tobi While it is possible to define such a syntax, I want to strongly discourage you from taking that path. You would either have to do a lot of low level programming to account for all the ways your users might use slightly different syntax than you intended, or you would still have to accept allcatcodes
to be frozen, even if you adjust|
first. It is much better to just teach your users what an environment is.
– schtandard
2 days ago
@Tobi As a more general point, I do not believe the way to get people to use LaTeX is to require them to use as few syntactical constructs as possible, but rather to design a clear interface that reflects the semantics of the content that is to be typeset. That is the fundamental strength of LaTeX, after all. (LaTeX has already done most of the work for you, here, compared to its foundation TeX. If you provide the preamble, your users will only have to learn the rules for spaces and paragraphs and a select number of macros and environments, with a highly standardized syntax.)
– schtandard
2 days ago
add a comment |
If you really want this interface, you can parse through the text with TeX:
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@stop@stop%
longdefsays@parse#1[#2]%
#1%
ifx@stop#2else
how#2%
expandaftersays@parse
fi
longdefsays#1#2%
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
item[#1]%
says@parse #2[@stop]%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
letnormalbackslash@backslashchar
makeatother
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysTobi
[annoyed] Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
[rambling]
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
[resigned] But okay, I'll explain it to you again.
[lecturing] You just write textttnormalbackslash says, then a pair of braces containing the name of the person speakingdots
[pausing] Good, like that.
Now you open another pair of braces and put their dialogue in there.
Close the brace, and [happily] you're done.
enddocument
This has some downsides.
- The syntax is not very well suited to the use, I think. Whenever you input many paragraphs as an argument to a macro, stop and ask yourself if this really should be an environment
- More importantly, as a consequence of this, you can't use any macros that change
catcode
s inside of the text (likeverb
). In my example, I had to usetexttt
and@backslashchar
instead.
A better approach, in my opinion, would be the use of an environment and an active character. We do not want to make [
(or ]
) active, because that would break all optional arguments. If you are open to changing the syntax from [instruction]
to |instruction|
, we can do this quite nicely though.
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@speech#1%
item[#1]%
catcode`
newenvironmentdialogue%
letspeech@speech
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
=12
gdefverticalbar
catcode`
makeatother
begindocument
begindialogue
speechMinka
|quietly|Hello, are you there? |shouting| Is anyone there?
speechTobi
|annoyed| Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
|rambling|
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
|resigned| But okay, I'll explain it to you again.
|lecturing| In the verb|dialogue| environment, you just write verb|speech|, then a pair of braces containing the name of the person speakingdots
|pausing| Good, like that.
Now you just type on what they should say.
Close the brace, and |happily| you're done.
enddialogue
enddocument
I like your second solution.|
is as good for my users as[...]
and it seems way more stable. However thebegin
...end
might already be too complex. I'll check if I can define mysays
in a way that it could handle that internally (e.g.newcommandsays[2]begindialoguespeech#1#2enddialogue
... One reason for this is: the less the users need to write the more likely is it, that they will use latex (instead of Google Docs and mess up all the layout)
– Tobi
2 days ago
@Tobi While it is possible to define such a syntax, I want to strongly discourage you from taking that path. You would either have to do a lot of low level programming to account for all the ways your users might use slightly different syntax than you intended, or you would still have to accept allcatcodes
to be frozen, even if you adjust|
first. It is much better to just teach your users what an environment is.
– schtandard
2 days ago
@Tobi As a more general point, I do not believe the way to get people to use LaTeX is to require them to use as few syntactical constructs as possible, but rather to design a clear interface that reflects the semantics of the content that is to be typeset. That is the fundamental strength of LaTeX, after all. (LaTeX has already done most of the work for you, here, compared to its foundation TeX. If you provide the preamble, your users will only have to learn the rules for spaces and paragraphs and a select number of macros and environments, with a highly standardized syntax.)
– schtandard
2 days ago
add a comment |
If you really want this interface, you can parse through the text with TeX:
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@stop@stop%
longdefsays@parse#1[#2]%
#1%
ifx@stop#2else
how#2%
expandaftersays@parse
fi
longdefsays#1#2%
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
item[#1]%
says@parse #2[@stop]%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
letnormalbackslash@backslashchar
makeatother
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysTobi
[annoyed] Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
[rambling]
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
[resigned] But okay, I'll explain it to you again.
[lecturing] You just write textttnormalbackslash says, then a pair of braces containing the name of the person speakingdots
[pausing] Good, like that.
Now you open another pair of braces and put their dialogue in there.
Close the brace, and [happily] you're done.
enddocument
This has some downsides.
- The syntax is not very well suited to the use, I think. Whenever you input many paragraphs as an argument to a macro, stop and ask yourself if this really should be an environment
- More importantly, as a consequence of this, you can't use any macros that change
catcode
s inside of the text (likeverb
). In my example, I had to usetexttt
and@backslashchar
instead.
A better approach, in my opinion, would be the use of an environment and an active character. We do not want to make [
(or ]
) active, because that would break all optional arguments. If you are open to changing the syntax from [instruction]
to |instruction|
, we can do this quite nicely though.
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@speech#1%
item[#1]%
catcode`
newenvironmentdialogue%
letspeech@speech
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
=12
gdefverticalbar
catcode`
makeatother
begindocument
begindialogue
speechMinka
|quietly|Hello, are you there? |shouting| Is anyone there?
speechTobi
|annoyed| Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
|rambling|
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
|resigned| But okay, I'll explain it to you again.
|lecturing| In the verb|dialogue| environment, you just write verb|speech|, then a pair of braces containing the name of the person speakingdots
|pausing| Good, like that.
Now you just type on what they should say.
Close the brace, and |happily| you're done.
enddialogue
enddocument
If you really want this interface, you can parse through the text with TeX:
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@stop@stop%
longdefsays@parse#1[#2]%
#1%
ifx@stop#2else
how#2%
expandaftersays@parse
fi
longdefsays#1#2%
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
item[#1]%
says@parse #2[@stop]%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
letnormalbackslash@backslashchar
makeatother
begindocument
saysMinka[quietly]Hello, are you there? [shouting] Is anyone there?
saysTobi
[annoyed] Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
[rambling]
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
[resigned] But okay, I'll explain it to you again.
[lecturing] You just write textttnormalbackslash says, then a pair of braces containing the name of the person speakingdots
[pausing] Good, like that.
Now you open another pair of braces and put their dialogue in there.
Close the brace, and [happily] you're done.
enddocument
This has some downsides.
- The syntax is not very well suited to the use, I think. Whenever you input many paragraphs as an argument to a macro, stop and ask yourself if this really should be an environment
- More importantly, as a consequence of this, you can't use any macros that change
catcode
s inside of the text (likeverb
). In my example, I had to usetexttt
and@backslashchar
instead.
A better approach, in my opinion, would be the use of an environment and an active character. We do not want to make [
(or ]
) active, because that would break all optional arguments. If you are open to changing the syntax from [instruction]
to |instruction|
, we can do this quite nicely though.
documentclassarticle
usepackageenumitem
newlengthwidest
settowidthwidesttextbfLongest Name in document
makeatletter
def@speech#1%
item[#1]%
catcode`
newenvironmentdialogue%
letspeech@speech
begindescription[leftmargin=dimexprwidest+labelseprelax,labelindent=0pt,labelwidth=widest]%
%
enddescription%
defhow#1%
ifhmodeunskip fi
textsl(#1)%
~ignorespaces
=12
gdefverticalbar
catcode`
makeatother
begindocument
begindialogue
speechMinka
|quietly|Hello, are you there? |shouting| Is anyone there?
speechTobi
|annoyed| Oh, don't be so fearful.
You know I'm here!
Just don't concentrate on what you're doing and you'll be fine.
|rambling|
It's not like a lot could go wrong anyway.
I mean, it's just a program, your computer won't literally explode.
If you somehow mess it up completely, we'll just reinstall it and you can try again.
|resigned| But okay, I'll explain it to you again.
|lecturing| In the verb|dialogue| environment, you just write verb|speech|, then a pair of braces containing the name of the person speakingdots
|pausing| Good, like that.
Now you just type on what they should say.
Close the brace, and |happily| you're done.
enddialogue
enddocument
edited 2 days ago
answered 2 days ago
schtandardschtandard
3,7731 gold badge12 silver badges28 bronze badges
3,7731 gold badge12 silver badges28 bronze badges
I like your second solution.|
is as good for my users as[...]
and it seems way more stable. However thebegin
...end
might already be too complex. I'll check if I can define mysays
in a way that it could handle that internally (e.g.newcommandsays[2]begindialoguespeech#1#2enddialogue
... One reason for this is: the less the users need to write the more likely is it, that they will use latex (instead of Google Docs and mess up all the layout)
– Tobi
2 days ago
@Tobi While it is possible to define such a syntax, I want to strongly discourage you from taking that path. You would either have to do a lot of low level programming to account for all the ways your users might use slightly different syntax than you intended, or you would still have to accept allcatcodes
to be frozen, even if you adjust|
first. It is much better to just teach your users what an environment is.
– schtandard
2 days ago
@Tobi As a more general point, I do not believe the way to get people to use LaTeX is to require them to use as few syntactical constructs as possible, but rather to design a clear interface that reflects the semantics of the content that is to be typeset. That is the fundamental strength of LaTeX, after all. (LaTeX has already done most of the work for you, here, compared to its foundation TeX. If you provide the preamble, your users will only have to learn the rules for spaces and paragraphs and a select number of macros and environments, with a highly standardized syntax.)
– schtandard
2 days ago
add a comment |
I like your second solution.|
is as good for my users as[...]
and it seems way more stable. However thebegin
...end
might already be too complex. I'll check if I can define mysays
in a way that it could handle that internally (e.g.newcommandsays[2]begindialoguespeech#1#2enddialogue
... One reason for this is: the less the users need to write the more likely is it, that they will use latex (instead of Google Docs and mess up all the layout)
– Tobi
2 days ago
@Tobi While it is possible to define such a syntax, I want to strongly discourage you from taking that path. You would either have to do a lot of low level programming to account for all the ways your users might use slightly different syntax than you intended, or you would still have to accept allcatcodes
to be frozen, even if you adjust|
first. It is much better to just teach your users what an environment is.
– schtandard
2 days ago
@Tobi As a more general point, I do not believe the way to get people to use LaTeX is to require them to use as few syntactical constructs as possible, but rather to design a clear interface that reflects the semantics of the content that is to be typeset. That is the fundamental strength of LaTeX, after all. (LaTeX has already done most of the work for you, here, compared to its foundation TeX. If you provide the preamble, your users will only have to learn the rules for spaces and paragraphs and a select number of macros and environments, with a highly standardized syntax.)
– schtandard
2 days ago
I like your second solution.
|
is as good for my users as [...]
and it seems way more stable. However the begin
... end
might already be too complex. I'll check if I can define my says
in a way that it could handle that internally (e.g. newcommandsays[2]begindialoguespeech#1#2enddialogue
... One reason for this is: the less the users need to write the more likely is it, that they will use latex (instead of Google Docs and mess up all the layout)– Tobi
2 days ago
I like your second solution.
|
is as good for my users as [...]
and it seems way more stable. However the begin
... end
might already be too complex. I'll check if I can define my says
in a way that it could handle that internally (e.g. newcommandsays[2]begindialoguespeech#1#2enddialogue
... One reason for this is: the less the users need to write the more likely is it, that they will use latex (instead of Google Docs and mess up all the layout)– Tobi
2 days ago
@Tobi While it is possible to define such a syntax, I want to strongly discourage you from taking that path. You would either have to do a lot of low level programming to account for all the ways your users might use slightly different syntax than you intended, or you would still have to accept all
catcodes
to be frozen, even if you adjust |
first. It is much better to just teach your users what an environment is.– schtandard
2 days ago
@Tobi While it is possible to define such a syntax, I want to strongly discourage you from taking that path. You would either have to do a lot of low level programming to account for all the ways your users might use slightly different syntax than you intended, or you would still have to accept all
catcodes
to be frozen, even if you adjust |
first. It is much better to just teach your users what an environment is.– schtandard
2 days ago
@Tobi As a more general point, I do not believe the way to get people to use LaTeX is to require them to use as few syntactical constructs as possible, but rather to design a clear interface that reflects the semantics of the content that is to be typeset. That is the fundamental strength of LaTeX, after all. (LaTeX has already done most of the work for you, here, compared to its foundation TeX. If you provide the preamble, your users will only have to learn the rules for spaces and paragraphs and a select number of macros and environments, with a highly standardized syntax.)
– schtandard
2 days ago
@Tobi As a more general point, I do not believe the way to get people to use LaTeX is to require them to use as few syntactical constructs as possible, but rather to design a clear interface that reflects the semantics of the content that is to be typeset. That is the fundamental strength of LaTeX, after all. (LaTeX has already done most of the work for you, here, compared to its foundation TeX. If you provide the preamble, your users will only have to learn the rules for spaces and paragraphs and a select number of macros and environments, with a highly standardized syntax.)
– schtandard
2 days 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%2f495885%2fhow-is-it-possible-to-use-square-brackets-as-shorthand-commands%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
It is possible, but an input syntax like
saysMinkahowquietly Hello, are you there? howshouting Is anyone there?
as @user605895 seems to be suggesting looks like cleaner markup to me.– frougon
Jun 15 at 11:32
Yes, but sqare brackets arebway easier to explain to our users.
– Tobi
Jun 15 at 17:20
Okay, please see my answer below.
– frougon
Jun 15 at 19:01