-
-
Save vermiculus/6da61223fea9906dab91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Reads one paragraph from each IOR stream #1 and #2 into boxes #3 and | |
% #4. The streams must be open. | |
\cs_new:Npn \fncypoem_read_par:NNNN #1 #2 #3 #4 { | |
\ior_if_eof:NT { #1 } { | |
\typeout{!~read~error~1} | |
} | |
\ior_if_eof:NT { #2 } { | |
\typeout{!~read~error~2} | |
} | |
\seq_new:N \l_parA_lines_seq | |
\seq_new:N \l_parB_lines_seq | |
\int_new:N \l_parA_line_no_int | |
\int_new:N \l_parB_line_no_int | |
% Prime line buffer to trick \bool_until_do: | |
\tl_set:N \l_tmpa_tl { line } | |
% Read lines into hboxes and pump them into token lists until you hit a | |
% blank line or the end of the paragraph | |
\bool_until_do:Nn { \tl_if_empty_p:N \l_tmpa_tl || \ior_if_eof_p:N { #1 }} { | |
% Save name as TMP_B | |
\tl_set:Nn \l_tmpb_tl { | |
l_parA_hbox \int_use:N { \l_parA_line_no_int } _box | |
} | |
\box_new:c { \tl_use:N \l_tmpb_tl } | |
% Read line into TMP_A | |
\ior_get_str:NN { #1 } \l_tmpa_tl | |
\hbox_set:cn { \tl_use:N \l_tmpb_tl } | |
{ \tl_use:N \l_tmpa_tl } % does not account for long lines | |
\seq_put_right:NV \l_parA_lines_seq { \use:c { \tl_use:N \l_tmpb_tl } } | |
} | |
\tl_set:N \l_tmpa_tl { line } % now do it for #2 | |
\bool_until_do:Nn { \tl_if_empty_p:N \l_tmpa_tl || \ior_if_eof_p:N { #2 }} { | |
\tl_set:Nn \l_tmpb_tl { l_parA_hbox \int_use:N { \l_parA_line_no_int } _box } | |
\box_new:c { \tl_use:N \l_tmpb_tl } | |
\ior_get_str:NN { #1 } \l_tmpa_tl | |
\hbox_set:cn { \tl_use:N \l_tmpb_tl } { \tl_use:N \l_tmpa_tl } | |
\seq_put_right:NV \l_parA_lines_seq { \use:c { \l_tmpb_tl } } | |
} | |
% Set pack the vboxes | |
\vbox_set:Nn { #3 } { \l_parA_tl } % I-have-no-idea-what-I-am-doing.jpg | |
\vbox_set:Nn { #4 } { \l_parB_tl } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment