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;








2















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?












share|improve this question
























  • 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

















2















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?












share|improve this question
























  • 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













2












2








2








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?












share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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

















  • 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
















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










3 Answers
3






active

oldest

votes


















6














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


Screenshot



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


Screenshot






share|improve this answer

























  • 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


















3














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





share|improve this answer























  • I know how to define macros. The question was about square brackets

    – Tobi
    Jun 15 at 17:22


















0














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


MWE output



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 catcodes inside of the text (like verb). In my example, I had to use texttt 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





share|improve this answer

























  • 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 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













Your Answer








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

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

else
createEditor();

);

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



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%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









6














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


Screenshot



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


Screenshot






share|improve this answer

























  • 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















6














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


Screenshot



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


Screenshot






share|improve this answer

























  • 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













6












6








6







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


Screenshot



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


Screenshot






share|improve this answer















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


Screenshot



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


Screenshot







share|improve this answer














share|improve this answer



share|improve this answer








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 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

















  • 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
















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













3














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





share|improve this answer























  • I know how to define macros. The question was about square brackets

    – Tobi
    Jun 15 at 17:22















3














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





share|improve this answer























  • I know how to define macros. The question was about square brackets

    – Tobi
    Jun 15 at 17:22













3












3








3







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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











0














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


MWE output



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 catcodes inside of the text (like verb). In my example, I had to use texttt 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





share|improve this answer

























  • 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 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















0














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


MWE output



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 catcodes inside of the text (like verb). In my example, I had to use texttt 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





share|improve this answer

























  • 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 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













0












0








0







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


MWE output



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 catcodes inside of the text (like verb). In my example, I had to use texttt 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





share|improve this answer















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


MWE output



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 catcodes inside of the text (like verb). In my example, I had to use texttt 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






share|improve this answer














share|improve this answer



share|improve this answer








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 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 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












  • @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
















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

















draft saved

draft discarded
















































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


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

But avoid


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

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

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




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f495885%2fhow-is-it-possible-to-use-square-brackets-as-shorthand-commands%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form