# Let pmx print two pieces of music in same document

I am just learning to use musixtex and its preprocessor pmx, and am trying to typeset and print a little evening song for a small group of people.
Since it would easily fit twice on an A4 paper, I would like to have it actually printed there twice as well, in order to not waste too much paper. However, I can't figure out how to have either pmx or musixtex itself printing two pieces of music in the same document. I'm quite sure this should be possible rather easily, since Rainer Dunker dedicates the problems arising from this technique while handling lyrics section 3.10.1 in his musixlyr 2.1c documentation, and takes it obviously for granted that one will be able to implement it oneself, since he gives no example.

I would prefer a solution already in the pmx file, since I plan to make minor modifications to the file later, and don't want to edit the .tex-file over and over again (anyway I think it's far more elegant to have only one inputting process per output file).

My working example (it's not completely minimal, but quite overseeable - and I therefore think it's alright) is the following .pmx-file:

% nstaves
1
% ninstr
1
% mtrnuml
4
% mtrdenl
4
% mtrnump
0
% mtrdenp
6
% npickup
0
% nkeys
-1
% npages
0
% nsystems
3
% musicsize
20
% frackindent
0
% Names of (n) instruments:

%Clefs
t
%where to write Output (SaabundOn.tex)?
./

%%%%% BODY
% Title
Tt
Saabund on j\"{a}lle \"{o}\"{o}

%% Print bar numbers?
\\nobarnumbers\

%% Vertical Spacing between systems and ensuring to use A4 paper
Ac4e

%%%%Beginn of music input
% Text (first line)
"Saa-bund on j\"{a}-lle \"{o}\"{o}, mis mei-le t\"{a}h-te-de vaik-set ra-hu toob."

% Bar 1
f24 f4 f4 /

% Bar 2
g4d4 a8 f4 oc f4 /

% Bar 3
b4d4 c8 a4 f8 a8 /

% Bar 4
a84 g8 f8 e8 f2 oc /

% Text (second line)
"L\~{o}pp-e-nud p\"{a}ev-a-t\"{o}\"{o} ja puh-ke-aeg ta-sa v\"{a}rs-keid j\~{o}u-de koob."

% Bar 5
a24 a4 a4 /

% Bar 6
b4d4 c8 a4 oc a4 /

% Bar 7
g4d4 a8 f4 oc a8 c8 /

% Bar 8
c85 b8 a8 g8 a2 oc /

% Text (third line)
"Kuu, s\"{a}-rav kuu, h\~{o}-be-da-ne kuu uj-ub o-ma val-gus-voos."

% Bar 9
c25 a44 f4 /

% Bar 10
c24 oc f84 c85 a8 f8 /

% Bar 11
c24 oc f8 e8 d8 c8 /

% Bar 12
b43 c4 f2 /

%There has to be a line break after the last bar, otherwise the bar won't appear in the score.

• maybe someone could add a pmx tag? Apr 9, 2018 at 14:03

I saved your code in the file mattu.pmx and ran

pmxab mattu && musixtex mattu && pdfcrop mattu


obtaining the PDF file mattu-crop.pdf

that you can include as many times as you wish with \includegraphics{mattu-crop} (possibly with options for the width).

• Yes, I meanwhile endet up with (almost) the same workaround (I don't crop the pdf when creating, but when importing (via \includegraphics[trim = 16.5mm 140mm 0mm 20mm, clip = true]{mattu.pdf})). I didn't dare posting it as an answer so far, since I feel it's only a workaround compared to a solution using only one script. However, I have one question left to your solution: Is there any quality loss expected, compared to a straight-forward solution? I astonishedly discoverd that the text is still searchable after this treatment. Apr 15, 2018 at 11:25
• @mattu Including a PDF in a PDF is quite safe and fonts are preserved. Being a vectorial format, it can be scaled at will. Apr 15, 2018 at 12:40
• Sadly I can not yet upvote your answer (since you took the time and it does the job, I wanted to have been done). But I want to keep the "accept answer" until there comes an answer dealing with the one-script-one-output-thing. So my thanks to you I can, until further notice, only show like this: Thanks a lot! Apr 15, 2018 at 13:06
• I forgot to mention: The \includegraphics command run on a pdf file does need the package pdfpages, which can be accessed by including \usepackage{pdfpages} in the preamble. Apr 15, 2018 at 13:09
• @mattu No, graphicx is sufficient. Apr 15, 2018 at 13:22

Andre van Ryckeghem gave me a pure PMX solution on the musixtex and related software mailing list, using in-line TeX for defining a macro to start another piece of music in the same PMX document.

The following type 4 in-line TeX command to PMX (refering to the terminology of the PMX manual) defines the macro:

---
\input musixtex
\makeatletter
\def\Song#1#2#3{%
\zcharnote{10}{%
\getcurpos\kern-\y@v\kern-\sign@skip\kern-\clef@skip\hskip-1\parindent
\raise #1\internote\hbox to \hsize{\hss {\BIgtype #2}\hss #3}}}%
\makeatother
---


So \Song{x}{y}{z} will have to be used at the first input block of the song, whose title it defines. It takes three arguments: x is a number, indicating how much (how many \internote distances) the title is positioned above the first staff. y is the title. And z is the composer's name.
\BIgtype, or a bit smaller \bigfont, is the (MusiXTeX command for the) font size of the title. More I don't understand from this definition.

The fact that the page will be full if we print two pieces on it will change the layout a bit. To get almost the same output as with the optically very satisfying solution that user egreg suggested, we will have to adjust the top and bottom margin of the page a bit and shrink the vertical space between title and first staff. For all the three issues I found the solution in the "Changing the Page Layout in PMX" document in the tips and tricks section of the Werner Icking Music Archive.
I still like the other solution optically better, because if you cut the page in two pieces (as designated) the margins will be more equal then. I feel confident this can be achieved in this solution with the AI option of PMX, but for the moment I am fine with this solution as it is.

The whole .pmx-file then looks as follows:

---
\input musixtex
\makeatletter
\def\Song#1#2#3{%
\zcharnote{10}{%
\getcurpos\kern-\y@v\kern-\sign@skip\kern-\clef@skip\hskip-1\parindent
\raise #1\internote\hbox to \hsize{\hss {\BIgtype #2}\hss #3}}}%
\makeatother
---
% nstaves
1
% ninstr
1
% mtrnuml
4
% mtrdenl
4
% mtrnump
0
% mtrdenp
6
% npickup
0
% nkeys
-1

% npages
1
% nsystems
8
% musicsize
20
% frackindent
0
% names of (n) instruments:

% Clefs
t
% where to write the output?
./

%%%%% BODY
%% Title
%commented out, since it is easier to add a title with in-line TeX, if one wants to shrink the space between the title and the first staff, compare below
%Tt
%Saabund on j\"{a}lle \"{o}\"{o}

%% Global PMX intrinsic options
Ac4e

%% Other global options (provided via in-line TeX)
%Get following "centerline" (title) 2pt up on the page (here using the command surprisingly lowers the title, otherwise it would have been voffset=18pt or something)
\\voffset=-2pt\
%The title nicely centered and with same fontsize and -type as with Tt
\\centerline{\BIgtype{Saabund on j\"{a}lle \"{o}\"{o}}}\
%shrink the vertical space between title and first staff by 3 Interlignes
\\vskip-3\Interligne\

%Don't print bar numbers at beginning of system
\\nobarnumbers\

%Add space on the bottom of all pages
\\let\ejectsav\eject\
\\def\eject{\vskip+7\Interligne\ejectsav}\

%% Song
% Text (first line)
"Saa-bund on j\"{a}-lle \"{o}\"{o}, mis mei-le t\"{a}h-te-de vaik-set ra-hu toob."
\lyrraise{1}{b-20pt}\

% Bar 1
f24 f4 f4 /

% Bar 2
g4d4 a8 f4 oc f4 /

% Bar 3
b4d4 c8 a4 f8 a8 /

% Bar 4
[ a84 g8 ] [ f8 e8 ] f2 oc /

% Text (second line)
"L\~{o}pp-e-nud p\"{a}ev-a-t\"{o}\"{o} ja puh-ke-aeg ta-sa v\"{a}rs-keid j\~{o}u-de koob."

% Bar 5
a24 a4 a4 /

% Bar 6
b4d4 c8 a4 oc a4 /

% Bar 7
g4d4 a8 f4 oc a8 c8 /

% Bar 8
[ c85 b8 ] [ a8 g8 ] a2 oc /

% Text (third line)
"Kuu, s\"{a}-rav kuu, h\~{o}-be-da-ne kuu uj-ub o-ma val-gus-voos."

% Bar 9
c25 a44 f4 /

% Bar 10
c24 oc f84 c85 a8 f8 /

% Bar 11
c24 oc [ f8 e8 ] [ d8 c8 ] /

% Bar 12
b43 c4 f2 /

%% Second song
% Force a line break at line 5, with a movement break of 16 \internote's vertical space
L5M+16
% Giving the meter of the new piece with a "meter change":
m4406
% Naming the title
\\\def\titel{Saabund on j\"{a}lle \"{o}\"{o}}\

% Text (first line)
"Saa-bund on j\"{a}-lle \"{o}\"{o}, mis mei-le t\"{a}h-te-de vaik-set ra-hu toob."

% Bar 1
f24 f4 f4 /
% Applying the above defined macro "Song" at the beginning of the first input block
\Song{12}{\titel}{\lower2\Interligne\llap{}}\

% Bar 2
g4d4 a8 f4 oc f4 /

% Bar 3
b4d4 c8 a4 f8 a8 /

% Bar 4
[ a84 g8 ] [ f8 e8 ] f2 oc /

% Text (second line)
"L\~{o}pp-e-nud p\"{a}ev-a-t\"{o}\"{o} ja puh-ke-aeg ta-sa v\"{a}rs-keid j\~{o}u-de koob."

% Bar 5
a24 a4 a4 /

% Bar 6
b4d4 c8 a4 oc a4 /

% Bar 7
g4d4 a8 f4 oc a8 c8 /

% Bar 8
[ c85 b8 ] [ a8 g8 ] a2 oc /

% Text (third line)
"Kuu, s\"{a}-rav kuu, h\~{o}-be-da-ne kuu uj-ub o-ma val-gus-voos."

% Bar 9
c25 a44 f4 /

% Bar 10
c24 oc f84 c85 a8 f8 /

% Bar 11
c24 oc [ f8 e8 ] [ d8 c8 ] /

% Bar 12
b43 c4 f2 /

• I am not sure if I want to accept this answer, since there is quite a bit of code involved, I don't have any clue of. Jun 9, 2018 at 15:15