Automatically formatting mesostics
A mesostic is poem/text similar to an acrostic except the "spine word" runs down the middle. Wiki's article explains it ok.
The format was pioneered by the composer John Cage and as the years went on he added more rules and began to use it to "write through" large texts (like Walden) generating hundreds or more mesostic poems. Eventually he got some people to mostly automate the process via software.
I've created my own mesostic generator. Here is an example that it produced using Poe's The Raven with the spine word "Lenore":
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
This can be achieved, roughly, with the following code:
documentclass[11pt]{memoir}
usepackage{fancyvrb}
usepackage{DejaVuSansMono}
begin{document}
begin{Verbatim}[xleftmargin=-35mm,commandchars=\{}]
neartextbf{L}y napping,
camtextbf{E} a
tappitextbf{N}g,
as textbf{O}f
gently textbf{R}apping,
at my chambtextbf{E}r door.
end{Verbatim}
end{document}
My mesostic generator is written in Lua and automatically adds enough spaces on the left to get the spine to line up down the center (plus I add the bold face stuff).
This works wonderfully for monospaced fonts. When I look through Cage's books I see he uses proportional fonts and yet still retains the formatting with the spine running perfectly down the center. I'm guessing that this was done manually by the typesetter.
So I'm wondering if anyone has any ideas about how to automatically format mesostics using proportional fonts within TeX/LaTeX?
Couple of notes:
A solution in LuaLaTeX would be fine.
In Cage's and my mesostics, all the letters are converted to lowercase with only the spine letters in caps. This is something that might be used to help format things?
Cage's rules limit the total number of characters in a line to 90 or so (45 character limit on either side of the spine letter). I follow this in my software. In fact I change the font size automatically when the lines get long.
poetry mesostic
add a comment |
A mesostic is poem/text similar to an acrostic except the "spine word" runs down the middle. Wiki's article explains it ok.
The format was pioneered by the composer John Cage and as the years went on he added more rules and began to use it to "write through" large texts (like Walden) generating hundreds or more mesostic poems. Eventually he got some people to mostly automate the process via software.
I've created my own mesostic generator. Here is an example that it produced using Poe's The Raven with the spine word "Lenore":
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
This can be achieved, roughly, with the following code:
documentclass[11pt]{memoir}
usepackage{fancyvrb}
usepackage{DejaVuSansMono}
begin{document}
begin{Verbatim}[xleftmargin=-35mm,commandchars=\{}]
neartextbf{L}y napping,
camtextbf{E} a
tappitextbf{N}g,
as textbf{O}f
gently textbf{R}apping,
at my chambtextbf{E}r door.
end{Verbatim}
end{document}
My mesostic generator is written in Lua and automatically adds enough spaces on the left to get the spine to line up down the center (plus I add the bold face stuff).
This works wonderfully for monospaced fonts. When I look through Cage's books I see he uses proportional fonts and yet still retains the formatting with the spine running perfectly down the center. I'm guessing that this was done manually by the typesetter.
So I'm wondering if anyone has any ideas about how to automatically format mesostics using proportional fonts within TeX/LaTeX?
Couple of notes:
A solution in LuaLaTeX would be fine.
In Cage's and my mesostics, all the letters are converted to lowercase with only the spine letters in caps. This is something that might be used to help format things?
Cage's rules limit the total number of characters in a line to 90 or so (45 character limit on either side of the spine letter). I follow this in my software. In fact I change the font size automatically when the lines get long.
poetry mesostic
Can't you use a tabular with 3 columns (and no space between the columns)?
– Ulrike Fischer
2 hours ago
I'm assuming that you mean the left "wing words" would be in one column on the left, the spine letter in a column in the middle, and then the right wing words in a third column on the right. And then just center the middle column and add the other columns? My concern would be that you'd lose some typesetting beauty by not having the letters on either side of the spine letter be properly and automatically spaced.
– bfootdav
2 hours ago
It should be not so difficult to insert the kerning manually.
– Ulrike Fischer
1 hour ago
I have no idea how one would automate inserting the kerning. I'm also not sure how one would go about centering one column of three on a page.
– bfootdav
1 hour ago
add a comment |
A mesostic is poem/text similar to an acrostic except the "spine word" runs down the middle. Wiki's article explains it ok.
The format was pioneered by the composer John Cage and as the years went on he added more rules and began to use it to "write through" large texts (like Walden) generating hundreds or more mesostic poems. Eventually he got some people to mostly automate the process via software.
I've created my own mesostic generator. Here is an example that it produced using Poe's The Raven with the spine word "Lenore":
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
This can be achieved, roughly, with the following code:
documentclass[11pt]{memoir}
usepackage{fancyvrb}
usepackage{DejaVuSansMono}
begin{document}
begin{Verbatim}[xleftmargin=-35mm,commandchars=\{}]
neartextbf{L}y napping,
camtextbf{E} a
tappitextbf{N}g,
as textbf{O}f
gently textbf{R}apping,
at my chambtextbf{E}r door.
end{Verbatim}
end{document}
My mesostic generator is written in Lua and automatically adds enough spaces on the left to get the spine to line up down the center (plus I add the bold face stuff).
This works wonderfully for monospaced fonts. When I look through Cage's books I see he uses proportional fonts and yet still retains the formatting with the spine running perfectly down the center. I'm guessing that this was done manually by the typesetter.
So I'm wondering if anyone has any ideas about how to automatically format mesostics using proportional fonts within TeX/LaTeX?
Couple of notes:
A solution in LuaLaTeX would be fine.
In Cage's and my mesostics, all the letters are converted to lowercase with only the spine letters in caps. This is something that might be used to help format things?
Cage's rules limit the total number of characters in a line to 90 or so (45 character limit on either side of the spine letter). I follow this in my software. In fact I change the font size automatically when the lines get long.
poetry mesostic
A mesostic is poem/text similar to an acrostic except the "spine word" runs down the middle. Wiki's article explains it ok.
The format was pioneered by the composer John Cage and as the years went on he added more rules and began to use it to "write through" large texts (like Walden) generating hundreds or more mesostic poems. Eventually he got some people to mostly automate the process via software.
I've created my own mesostic generator. Here is an example that it produced using Poe's The Raven with the spine word "Lenore":
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
This can be achieved, roughly, with the following code:
documentclass[11pt]{memoir}
usepackage{fancyvrb}
usepackage{DejaVuSansMono}
begin{document}
begin{Verbatim}[xleftmargin=-35mm,commandchars=\{}]
neartextbf{L}y napping,
camtextbf{E} a
tappitextbf{N}g,
as textbf{O}f
gently textbf{R}apping,
at my chambtextbf{E}r door.
end{Verbatim}
end{document}
My mesostic generator is written in Lua and automatically adds enough spaces on the left to get the spine to line up down the center (plus I add the bold face stuff).
This works wonderfully for monospaced fonts. When I look through Cage's books I see he uses proportional fonts and yet still retains the formatting with the spine running perfectly down the center. I'm guessing that this was done manually by the typesetter.
So I'm wondering if anyone has any ideas about how to automatically format mesostics using proportional fonts within TeX/LaTeX?
Couple of notes:
A solution in LuaLaTeX would be fine.
In Cage's and my mesostics, all the letters are converted to lowercase with only the spine letters in caps. This is something that might be used to help format things?
Cage's rules limit the total number of characters in a line to 90 or so (45 character limit on either side of the spine letter). I follow this in my software. In fact I change the font size automatically when the lines get long.
poetry mesostic
poetry mesostic
edited 1 hour ago
bfootdav
asked 3 hours ago
bfootdavbfootdav
6381420
6381420
Can't you use a tabular with 3 columns (and no space between the columns)?
– Ulrike Fischer
2 hours ago
I'm assuming that you mean the left "wing words" would be in one column on the left, the spine letter in a column in the middle, and then the right wing words in a third column on the right. And then just center the middle column and add the other columns? My concern would be that you'd lose some typesetting beauty by not having the letters on either side of the spine letter be properly and automatically spaced.
– bfootdav
2 hours ago
It should be not so difficult to insert the kerning manually.
– Ulrike Fischer
1 hour ago
I have no idea how one would automate inserting the kerning. I'm also not sure how one would go about centering one column of three on a page.
– bfootdav
1 hour ago
add a comment |
Can't you use a tabular with 3 columns (and no space between the columns)?
– Ulrike Fischer
2 hours ago
I'm assuming that you mean the left "wing words" would be in one column on the left, the spine letter in a column in the middle, and then the right wing words in a third column on the right. And then just center the middle column and add the other columns? My concern would be that you'd lose some typesetting beauty by not having the letters on either side of the spine letter be properly and automatically spaced.
– bfootdav
2 hours ago
It should be not so difficult to insert the kerning manually.
– Ulrike Fischer
1 hour ago
I have no idea how one would automate inserting the kerning. I'm also not sure how one would go about centering one column of three on a page.
– bfootdav
1 hour ago
Can't you use a tabular with 3 columns (and no space between the columns)?
– Ulrike Fischer
2 hours ago
Can't you use a tabular with 3 columns (and no space between the columns)?
– Ulrike Fischer
2 hours ago
I'm assuming that you mean the left "wing words" would be in one column on the left, the spine letter in a column in the middle, and then the right wing words in a third column on the right. And then just center the middle column and add the other columns? My concern would be that you'd lose some typesetting beauty by not having the letters on either side of the spine letter be properly and automatically spaced.
– bfootdav
2 hours ago
I'm assuming that you mean the left "wing words" would be in one column on the left, the spine letter in a column in the middle, and then the right wing words in a third column on the right. And then just center the middle column and add the other columns? My concern would be that you'd lose some typesetting beauty by not having the letters on either side of the spine letter be properly and automatically spaced.
– bfootdav
2 hours ago
It should be not so difficult to insert the kerning manually.
– Ulrike Fischer
1 hour ago
It should be not so difficult to insert the kerning manually.
– Ulrike Fischer
1 hour ago
I have no idea how one would automate inserting the kerning. I'm also not sure how one would go about centering one column of three on a page.
– bfootdav
1 hour ago
I have no idea how one would automate inserting the kerning. I'm also not sure how one would go about centering one column of three on a page.
– bfootdav
1 hour ago
add a comment |
3 Answers
3
active
oldest
votes
Disclaimer. The code below doesn't imply in any way whatsoever that I endorse or otherwise hold in esteem any aspect of John Cage's work.
The following approach splits the input at \
, then builds lines one by one, setting an hbox
where the width of the center letter is measured; the box will then consist of
- a box as wide as half the linewidth minus half the center letter's width, flush right;
- the center letter;
- a box like in step 1, but flush left.
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}
{
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
box_new:N l__mesostic_center_box
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_set:Nn l__mesostic_center_box { textbf{#2} }
hbox_to_wd:nn { linewidth }
{
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
hss #1
}
textbf{#2}
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
#3 hss
}
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
end{document}
Changing the font might be implemented by making a tentative typesetting and measuring each part in order to see whether it satisfies the constraints of being contained in the line width; in case of failure, stop, change the font size and repeat.
A variant that allows for an optional argument where to state a font or a font size (or both); also a check for a trailing \
is added. The main code has been simplified (thanks to jfbu for the idea).
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}[1]
{
#1
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
cs_generate_variant:Nn tl_if_empty:nT { x }
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
% check for a trailing \
tl_if_empty:xT { seq_item:Nn l__mesostic_body_seq { -1 } }
{
seq_pop_right:NN l__mesostic_body_seq l_tmpa_tl
}
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_to_wd:nn { linewidth }
{
hss
hbox_to_wd:nn { 0pt } { hss tl_lower_case:n { #1 } }
textbf{tl_upper_case:n { #2 }}
hbox_to_wd:nn { 0pt } { tl_lower_case:n { #3 } hss }
hss
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
begin{mesostic}[sffamilyfootnotesize]
NEAR|l|Y NAPPING \
CAM|e| A \
TAPPI|n|G \
AS |o|F \
GENTLY |r|APPING \
AT MY CHAMB|e|R DOOR \
end{mesostic}
kant[3]
end{document}
Wow! Thank you very much, egreg! I've marked this as answered but I'm going to play around with it for the next few days. If any questions come up I'll ping you. This is really cool and so much more versatile than my Verbatim solution.
– bfootdav
46 mins ago
@bfootdav Instead of doing tentative typesettings, it would be easy to add an optional argument for selecting font/size.
– egreg
42 mins ago
The font size is handled in my mesostic generating software and works ok especially since there can only be at most 91 characters in a line. The software generates .tex files. I experimented with line lengths and chose font sizes for various line lengths. I ended up only needing two sizes anyway.
– bfootdav
37 mins ago
add a comment |
documentclass{article}
makeatletter
defmesostic@end{end{mesostic}}
begingroupcatcode`^^Mactive
gdefmesostic@aux#1|#2|#3mesostic@aux%
{noindenthfill%
llap{MakeLowercase{#1}}%
textbf{MakeUppercase{#2}}%
rlap{MakeLowercase{#3}}%
hfillhbox{}par%
expandafter^^M}%
endgroup
newenvironment{mesostic}{parskip0ptrelax
obeylines
begingrouplccode`~`^^M
lowercase{endgroupdef~##1~}{%
defmesostic@tmp{##1}%
ifxmesostic@tmpmesostic@end
expandaftermesostic@end
else
mesostic@aux##1mesostic@aux
fi}%
}{}
makeatother
begin{document}
blah blah blah
noindent Xdotfill X
begin{mesostic}
near|L|y napping,
cam|E| a
tappi|N|g,
as |O|f
gently |R|apping,
at my chamb|E|r door.
end{mesostic}
noindent Xdotfill X
blah blah blah
noindent Xdotfill X
begin{mesostic}
NEAR|l|Y NAPPING,
CAM|e| A
TAPPI|n|G,
AS |o|F
GENTLY |r|APPING,
AT MY CHAMB|e|R DOOR.
end{mesostic}
noindent Xdotfill X
blah blah blah
end{document}
And using Xdotfill Xdotfill X
for the extra lines for context:
of course the input can be kept in the indented form aligning the letters; I deliberately flushed it to the left to show freedom of input.
– jfbu
32 mins ago
I also illustrated the uppercasing, which seems to have been on OP's list.
– jfbu
23 mins ago
add a comment |
documentclass{article}
makeatletter
{obeylineseveryeof{noexpand}%
gdefzzz#1{%
catcode`#1activescantokens{defzzzz{gdef#1}}%
zzzz##1^^M{makebox[.5textwidth][l]{textbf{string#1##1}}par}%
}}
defzz{flushrightobeylines%
letorzzz@Alph{0fiiftrue}}%
defendzz{endflushright}
begin{document}
begin{zz}
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
end{zz}
end{document}
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%2f470926%2fautomatically-formatting-mesostics%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
Disclaimer. The code below doesn't imply in any way whatsoever that I endorse or otherwise hold in esteem any aspect of John Cage's work.
The following approach splits the input at \
, then builds lines one by one, setting an hbox
where the width of the center letter is measured; the box will then consist of
- a box as wide as half the linewidth minus half the center letter's width, flush right;
- the center letter;
- a box like in step 1, but flush left.
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}
{
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
box_new:N l__mesostic_center_box
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_set:Nn l__mesostic_center_box { textbf{#2} }
hbox_to_wd:nn { linewidth }
{
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
hss #1
}
textbf{#2}
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
#3 hss
}
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
end{document}
Changing the font might be implemented by making a tentative typesetting and measuring each part in order to see whether it satisfies the constraints of being contained in the line width; in case of failure, stop, change the font size and repeat.
A variant that allows for an optional argument where to state a font or a font size (or both); also a check for a trailing \
is added. The main code has been simplified (thanks to jfbu for the idea).
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}[1]
{
#1
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
cs_generate_variant:Nn tl_if_empty:nT { x }
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
% check for a trailing \
tl_if_empty:xT { seq_item:Nn l__mesostic_body_seq { -1 } }
{
seq_pop_right:NN l__mesostic_body_seq l_tmpa_tl
}
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_to_wd:nn { linewidth }
{
hss
hbox_to_wd:nn { 0pt } { hss tl_lower_case:n { #1 } }
textbf{tl_upper_case:n { #2 }}
hbox_to_wd:nn { 0pt } { tl_lower_case:n { #3 } hss }
hss
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
begin{mesostic}[sffamilyfootnotesize]
NEAR|l|Y NAPPING \
CAM|e| A \
TAPPI|n|G \
AS |o|F \
GENTLY |r|APPING \
AT MY CHAMB|e|R DOOR \
end{mesostic}
kant[3]
end{document}
Wow! Thank you very much, egreg! I've marked this as answered but I'm going to play around with it for the next few days. If any questions come up I'll ping you. This is really cool and so much more versatile than my Verbatim solution.
– bfootdav
46 mins ago
@bfootdav Instead of doing tentative typesettings, it would be easy to add an optional argument for selecting font/size.
– egreg
42 mins ago
The font size is handled in my mesostic generating software and works ok especially since there can only be at most 91 characters in a line. The software generates .tex files. I experimented with line lengths and chose font sizes for various line lengths. I ended up only needing two sizes anyway.
– bfootdav
37 mins ago
add a comment |
Disclaimer. The code below doesn't imply in any way whatsoever that I endorse or otherwise hold in esteem any aspect of John Cage's work.
The following approach splits the input at \
, then builds lines one by one, setting an hbox
where the width of the center letter is measured; the box will then consist of
- a box as wide as half the linewidth minus half the center letter's width, flush right;
- the center letter;
- a box like in step 1, but flush left.
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}
{
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
box_new:N l__mesostic_center_box
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_set:Nn l__mesostic_center_box { textbf{#2} }
hbox_to_wd:nn { linewidth }
{
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
hss #1
}
textbf{#2}
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
#3 hss
}
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
end{document}
Changing the font might be implemented by making a tentative typesetting and measuring each part in order to see whether it satisfies the constraints of being contained in the line width; in case of failure, stop, change the font size and repeat.
A variant that allows for an optional argument where to state a font or a font size (or both); also a check for a trailing \
is added. The main code has been simplified (thanks to jfbu for the idea).
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}[1]
{
#1
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
cs_generate_variant:Nn tl_if_empty:nT { x }
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
% check for a trailing \
tl_if_empty:xT { seq_item:Nn l__mesostic_body_seq { -1 } }
{
seq_pop_right:NN l__mesostic_body_seq l_tmpa_tl
}
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_to_wd:nn { linewidth }
{
hss
hbox_to_wd:nn { 0pt } { hss tl_lower_case:n { #1 } }
textbf{tl_upper_case:n { #2 }}
hbox_to_wd:nn { 0pt } { tl_lower_case:n { #3 } hss }
hss
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
begin{mesostic}[sffamilyfootnotesize]
NEAR|l|Y NAPPING \
CAM|e| A \
TAPPI|n|G \
AS |o|F \
GENTLY |r|APPING \
AT MY CHAMB|e|R DOOR \
end{mesostic}
kant[3]
end{document}
Wow! Thank you very much, egreg! I've marked this as answered but I'm going to play around with it for the next few days. If any questions come up I'll ping you. This is really cool and so much more versatile than my Verbatim solution.
– bfootdav
46 mins ago
@bfootdav Instead of doing tentative typesettings, it would be easy to add an optional argument for selecting font/size.
– egreg
42 mins ago
The font size is handled in my mesostic generating software and works ok especially since there can only be at most 91 characters in a line. The software generates .tex files. I experimented with line lengths and chose font sizes for various line lengths. I ended up only needing two sizes anyway.
– bfootdav
37 mins ago
add a comment |
Disclaimer. The code below doesn't imply in any way whatsoever that I endorse or otherwise hold in esteem any aspect of John Cage's work.
The following approach splits the input at \
, then builds lines one by one, setting an hbox
where the width of the center letter is measured; the box will then consist of
- a box as wide as half the linewidth minus half the center letter's width, flush right;
- the center letter;
- a box like in step 1, but flush left.
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}
{
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
box_new:N l__mesostic_center_box
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_set:Nn l__mesostic_center_box { textbf{#2} }
hbox_to_wd:nn { linewidth }
{
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
hss #1
}
textbf{#2}
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
#3 hss
}
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
end{document}
Changing the font might be implemented by making a tentative typesetting and measuring each part in order to see whether it satisfies the constraints of being contained in the line width; in case of failure, stop, change the font size and repeat.
A variant that allows for an optional argument where to state a font or a font size (or both); also a check for a trailing \
is added. The main code has been simplified (thanks to jfbu for the idea).
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}[1]
{
#1
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
cs_generate_variant:Nn tl_if_empty:nT { x }
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
% check for a trailing \
tl_if_empty:xT { seq_item:Nn l__mesostic_body_seq { -1 } }
{
seq_pop_right:NN l__mesostic_body_seq l_tmpa_tl
}
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_to_wd:nn { linewidth }
{
hss
hbox_to_wd:nn { 0pt } { hss tl_lower_case:n { #1 } }
textbf{tl_upper_case:n { #2 }}
hbox_to_wd:nn { 0pt } { tl_lower_case:n { #3 } hss }
hss
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
begin{mesostic}[sffamilyfootnotesize]
NEAR|l|Y NAPPING \
CAM|e| A \
TAPPI|n|G \
AS |o|F \
GENTLY |r|APPING \
AT MY CHAMB|e|R DOOR \
end{mesostic}
kant[3]
end{document}
Disclaimer. The code below doesn't imply in any way whatsoever that I endorse or otherwise hold in esteem any aspect of John Cage's work.
The following approach splits the input at \
, then builds lines one by one, setting an hbox
where the width of the center letter is measured; the box will then consist of
- a box as wide as half the linewidth minus half the center letter's width, flush right;
- the center letter;
- a box like in step 1, but flush left.
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}
{
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
box_new:N l__mesostic_center_box
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_set:Nn l__mesostic_center_box { textbf{#2} }
hbox_to_wd:nn { linewidth }
{
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
hss #1
}
textbf{#2}
hbox_to_wd:nn { (linewidth-box_wd:N l__mesostic_center_box)/2 }
{
#3 hss
}
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
end{document}
Changing the font might be implemented by making a tentative typesetting and measuring each part in order to see whether it satisfies the constraints of being contained in the line width; in case of failure, stop, change the font size and repeat.
A variant that allows for an optional argument where to state a font or a font size (or both); also a check for a trailing \
is added. The main code has been simplified (thanks to jfbu for the idea).
documentclass{article}
usepackage{environ,xparse}
usepackage{kantlipsum} % for context
ExplSyntaxOn
NewEnviron{mesostic}[1]
{
#1
paraddvspace{topsep}
mesostic_build:V BODY
addvspace{topsep}
}
seq_new:N l__mesostic_body_seq
cs_generate_variant:Nn tl_if_empty:nT { x }
cs_new_protected:Nn mesostic_build:n
{
seq_set_split:Nnn l__mesostic_body_seq { \ } { #1 }
% check for a trailing \
tl_if_empty:xT { seq_item:Nn l__mesostic_body_seq { -1 } }
{
seq_pop_right:NN l__mesostic_body_seq l_tmpa_tl
}
seq_map_inline:Nn l__mesostic_body_seq
{
__mesostic_line:w ##1 q_stop
}
}
cs_generate_variant:Nn mesostic_build:n { V }
cs_new_protected:Npn __mesostic_line:w #1 | #2 | #3 q_stop
{
hbox_to_wd:nn { linewidth }
{
hss
hbox_to_wd:nn { 0pt } { hss tl_lower_case:n { #1 } }
textbf{tl_upper_case:n { #2 }}
hbox_to_wd:nn { 0pt } { tl_lower_case:n { #3 } hss }
hss
}
}
ExplSyntaxOff
begin{document}
kant[1]
begin{mesostic}
near|L|y napping, \
cam|E| a \
tappi|N|g, \
as |O|f \
gently |R|apping, \
at my chamb|E|r door.
end{mesostic}
kant[2]
begin{mesostic}[sffamilyfootnotesize]
NEAR|l|Y NAPPING \
CAM|e| A \
TAPPI|n|G \
AS |o|F \
GENTLY |r|APPING \
AT MY CHAMB|e|R DOOR \
end{mesostic}
kant[3]
end{document}
edited 27 mins ago
answered 1 hour ago
egregegreg
713k8618953184
713k8618953184
Wow! Thank you very much, egreg! I've marked this as answered but I'm going to play around with it for the next few days. If any questions come up I'll ping you. This is really cool and so much more versatile than my Verbatim solution.
– bfootdav
46 mins ago
@bfootdav Instead of doing tentative typesettings, it would be easy to add an optional argument for selecting font/size.
– egreg
42 mins ago
The font size is handled in my mesostic generating software and works ok especially since there can only be at most 91 characters in a line. The software generates .tex files. I experimented with line lengths and chose font sizes for various line lengths. I ended up only needing two sizes anyway.
– bfootdav
37 mins ago
add a comment |
Wow! Thank you very much, egreg! I've marked this as answered but I'm going to play around with it for the next few days. If any questions come up I'll ping you. This is really cool and so much more versatile than my Verbatim solution.
– bfootdav
46 mins ago
@bfootdav Instead of doing tentative typesettings, it would be easy to add an optional argument for selecting font/size.
– egreg
42 mins ago
The font size is handled in my mesostic generating software and works ok especially since there can only be at most 91 characters in a line. The software generates .tex files. I experimented with line lengths and chose font sizes for various line lengths. I ended up only needing two sizes anyway.
– bfootdav
37 mins ago
Wow! Thank you very much, egreg! I've marked this as answered but I'm going to play around with it for the next few days. If any questions come up I'll ping you. This is really cool and so much more versatile than my Verbatim solution.
– bfootdav
46 mins ago
Wow! Thank you very much, egreg! I've marked this as answered but I'm going to play around with it for the next few days. If any questions come up I'll ping you. This is really cool and so much more versatile than my Verbatim solution.
– bfootdav
46 mins ago
@bfootdav Instead of doing tentative typesettings, it would be easy to add an optional argument for selecting font/size.
– egreg
42 mins ago
@bfootdav Instead of doing tentative typesettings, it would be easy to add an optional argument for selecting font/size.
– egreg
42 mins ago
The font size is handled in my mesostic generating software and works ok especially since there can only be at most 91 characters in a line. The software generates .tex files. I experimented with line lengths and chose font sizes for various line lengths. I ended up only needing two sizes anyway.
– bfootdav
37 mins ago
The font size is handled in my mesostic generating software and works ok especially since there can only be at most 91 characters in a line. The software generates .tex files. I experimented with line lengths and chose font sizes for various line lengths. I ended up only needing two sizes anyway.
– bfootdav
37 mins ago
add a comment |
documentclass{article}
makeatletter
defmesostic@end{end{mesostic}}
begingroupcatcode`^^Mactive
gdefmesostic@aux#1|#2|#3mesostic@aux%
{noindenthfill%
llap{MakeLowercase{#1}}%
textbf{MakeUppercase{#2}}%
rlap{MakeLowercase{#3}}%
hfillhbox{}par%
expandafter^^M}%
endgroup
newenvironment{mesostic}{parskip0ptrelax
obeylines
begingrouplccode`~`^^M
lowercase{endgroupdef~##1~}{%
defmesostic@tmp{##1}%
ifxmesostic@tmpmesostic@end
expandaftermesostic@end
else
mesostic@aux##1mesostic@aux
fi}%
}{}
makeatother
begin{document}
blah blah blah
noindent Xdotfill X
begin{mesostic}
near|L|y napping,
cam|E| a
tappi|N|g,
as |O|f
gently |R|apping,
at my chamb|E|r door.
end{mesostic}
noindent Xdotfill X
blah blah blah
noindent Xdotfill X
begin{mesostic}
NEAR|l|Y NAPPING,
CAM|e| A
TAPPI|n|G,
AS |o|F
GENTLY |r|APPING,
AT MY CHAMB|e|R DOOR.
end{mesostic}
noindent Xdotfill X
blah blah blah
end{document}
And using Xdotfill Xdotfill X
for the extra lines for context:
of course the input can be kept in the indented form aligning the letters; I deliberately flushed it to the left to show freedom of input.
– jfbu
32 mins ago
I also illustrated the uppercasing, which seems to have been on OP's list.
– jfbu
23 mins ago
add a comment |
documentclass{article}
makeatletter
defmesostic@end{end{mesostic}}
begingroupcatcode`^^Mactive
gdefmesostic@aux#1|#2|#3mesostic@aux%
{noindenthfill%
llap{MakeLowercase{#1}}%
textbf{MakeUppercase{#2}}%
rlap{MakeLowercase{#3}}%
hfillhbox{}par%
expandafter^^M}%
endgroup
newenvironment{mesostic}{parskip0ptrelax
obeylines
begingrouplccode`~`^^M
lowercase{endgroupdef~##1~}{%
defmesostic@tmp{##1}%
ifxmesostic@tmpmesostic@end
expandaftermesostic@end
else
mesostic@aux##1mesostic@aux
fi}%
}{}
makeatother
begin{document}
blah blah blah
noindent Xdotfill X
begin{mesostic}
near|L|y napping,
cam|E| a
tappi|N|g,
as |O|f
gently |R|apping,
at my chamb|E|r door.
end{mesostic}
noindent Xdotfill X
blah blah blah
noindent Xdotfill X
begin{mesostic}
NEAR|l|Y NAPPING,
CAM|e| A
TAPPI|n|G,
AS |o|F
GENTLY |r|APPING,
AT MY CHAMB|e|R DOOR.
end{mesostic}
noindent Xdotfill X
blah blah blah
end{document}
And using Xdotfill Xdotfill X
for the extra lines for context:
of course the input can be kept in the indented form aligning the letters; I deliberately flushed it to the left to show freedom of input.
– jfbu
32 mins ago
I also illustrated the uppercasing, which seems to have been on OP's list.
– jfbu
23 mins ago
add a comment |
documentclass{article}
makeatletter
defmesostic@end{end{mesostic}}
begingroupcatcode`^^Mactive
gdefmesostic@aux#1|#2|#3mesostic@aux%
{noindenthfill%
llap{MakeLowercase{#1}}%
textbf{MakeUppercase{#2}}%
rlap{MakeLowercase{#3}}%
hfillhbox{}par%
expandafter^^M}%
endgroup
newenvironment{mesostic}{parskip0ptrelax
obeylines
begingrouplccode`~`^^M
lowercase{endgroupdef~##1~}{%
defmesostic@tmp{##1}%
ifxmesostic@tmpmesostic@end
expandaftermesostic@end
else
mesostic@aux##1mesostic@aux
fi}%
}{}
makeatother
begin{document}
blah blah blah
noindent Xdotfill X
begin{mesostic}
near|L|y napping,
cam|E| a
tappi|N|g,
as |O|f
gently |R|apping,
at my chamb|E|r door.
end{mesostic}
noindent Xdotfill X
blah blah blah
noindent Xdotfill X
begin{mesostic}
NEAR|l|Y NAPPING,
CAM|e| A
TAPPI|n|G,
AS |o|F
GENTLY |r|APPING,
AT MY CHAMB|e|R DOOR.
end{mesostic}
noindent Xdotfill X
blah blah blah
end{document}
And using Xdotfill Xdotfill X
for the extra lines for context:
documentclass{article}
makeatletter
defmesostic@end{end{mesostic}}
begingroupcatcode`^^Mactive
gdefmesostic@aux#1|#2|#3mesostic@aux%
{noindenthfill%
llap{MakeLowercase{#1}}%
textbf{MakeUppercase{#2}}%
rlap{MakeLowercase{#3}}%
hfillhbox{}par%
expandafter^^M}%
endgroup
newenvironment{mesostic}{parskip0ptrelax
obeylines
begingrouplccode`~`^^M
lowercase{endgroupdef~##1~}{%
defmesostic@tmp{##1}%
ifxmesostic@tmpmesostic@end
expandaftermesostic@end
else
mesostic@aux##1mesostic@aux
fi}%
}{}
makeatother
begin{document}
blah blah blah
noindent Xdotfill X
begin{mesostic}
near|L|y napping,
cam|E| a
tappi|N|g,
as |O|f
gently |R|apping,
at my chamb|E|r door.
end{mesostic}
noindent Xdotfill X
blah blah blah
noindent Xdotfill X
begin{mesostic}
NEAR|l|Y NAPPING,
CAM|e| A
TAPPI|n|G,
AS |o|F
GENTLY |r|APPING,
AT MY CHAMB|e|R DOOR.
end{mesostic}
noindent Xdotfill X
blah blah blah
end{document}
And using Xdotfill Xdotfill X
for the extra lines for context:
edited 36 mins ago
answered 42 mins ago
jfbujfbu
46.6k66148
46.6k66148
of course the input can be kept in the indented form aligning the letters; I deliberately flushed it to the left to show freedom of input.
– jfbu
32 mins ago
I also illustrated the uppercasing, which seems to have been on OP's list.
– jfbu
23 mins ago
add a comment |
of course the input can be kept in the indented form aligning the letters; I deliberately flushed it to the left to show freedom of input.
– jfbu
32 mins ago
I also illustrated the uppercasing, which seems to have been on OP's list.
– jfbu
23 mins ago
of course the input can be kept in the indented form aligning the letters; I deliberately flushed it to the left to show freedom of input.
– jfbu
32 mins ago
of course the input can be kept in the indented form aligning the letters; I deliberately flushed it to the left to show freedom of input.
– jfbu
32 mins ago
I also illustrated the uppercasing, which seems to have been on OP's list.
– jfbu
23 mins ago
I also illustrated the uppercasing, which seems to have been on OP's list.
– jfbu
23 mins ago
add a comment |
documentclass{article}
makeatletter
{obeylineseveryeof{noexpand}%
gdefzzz#1{%
catcode`#1activescantokens{defzzzz{gdef#1}}%
zzzz##1^^M{makebox[.5textwidth][l]{textbf{string#1##1}}par}%
}}
defzz{flushrightobeylines%
letorzzz@Alph{0fiiftrue}}%
defendzz{endflushright}
begin{document}
begin{zz}
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
end{zz}
end{document}
add a comment |
documentclass{article}
makeatletter
{obeylineseveryeof{noexpand}%
gdefzzz#1{%
catcode`#1activescantokens{defzzzz{gdef#1}}%
zzzz##1^^M{makebox[.5textwidth][l]{textbf{string#1##1}}par}%
}}
defzz{flushrightobeylines%
letorzzz@Alph{0fiiftrue}}%
defendzz{endflushright}
begin{document}
begin{zz}
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
end{zz}
end{document}
add a comment |
documentclass{article}
makeatletter
{obeylineseveryeof{noexpand}%
gdefzzz#1{%
catcode`#1activescantokens{defzzzz{gdef#1}}%
zzzz##1^^M{makebox[.5textwidth][l]{textbf{string#1##1}}par}%
}}
defzz{flushrightobeylines%
letorzzz@Alph{0fiiftrue}}%
defendzz{endflushright}
begin{document}
begin{zz}
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
end{zz}
end{document}
documentclass{article}
makeatletter
{obeylineseveryeof{noexpand}%
gdefzzz#1{%
catcode`#1activescantokens{defzzzz{gdef#1}}%
zzzz##1^^M{makebox[.5textwidth][l]{textbf{string#1##1}}par}%
}}
defzz{flushrightobeylines%
letorzzz@Alph{0fiiftrue}}%
defendzz{endflushright}
begin{document}
begin{zz}
nearLy napping,
camE a
tappiNg,
as Of
gently Rapping,
at my chambEr door.
end{zz}
end{document}
answered 6 mins ago
David CarlisleDavid Carlisle
486k4111221865
486k4111221865
add a comment |
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%2f470926%2fautomatically-formatting-mesostics%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
Can't you use a tabular with 3 columns (and no space between the columns)?
– Ulrike Fischer
2 hours ago
I'm assuming that you mean the left "wing words" would be in one column on the left, the spine letter in a column in the middle, and then the right wing words in a third column on the right. And then just center the middle column and add the other columns? My concern would be that you'd lose some typesetting beauty by not having the letters on either side of the spine letter be properly and automatically spaced.
– bfootdav
2 hours ago
It should be not so difficult to insert the kerning manually.
– Ulrike Fischer
1 hour ago
I have no idea how one would automate inserting the kerning. I'm also not sure how one would go about centering one column of three on a page.
– bfootdav
1 hour ago