LaTeX - score export
Hi
I would like to write a music book with latex including text and music.
Latex -> for the style of the text and the ease of use
Musescore -> for the scores
However, currently, i am exporting the score as a PNG file and then cut it in photoshop as Musescore exports all the page and not only the score.
It results that I never have the same width and I loose lot of time to adjust the width of each samples.
What should I do ?
Cheers
Comments
Maybe better use SVG?
In reply to Maybe better use SVG? by Jojo-Schmitz
Tₑχ/LᴬTᴇΧ don’t do SVG natively, but with a trick this is still the best way to go. You’ll need to have Inkscape installed.
Do this:
musica1.svg
inkscape -C --export-filename=musica1.pdf --export-type=pdf --export-pdf-version=1.4 musica1.svg
inkscape -C -z --export-pdf=musica1.pdf --export-pdf-version=1.4 musica1.svg
\DeclareGraphicsExtensions{.pdf,.eps,.png,.jpg}%
if you don’t have it yet, or add.pdf
to the list if you already have it\includegraphics[width=\linewidth]{musica1}%
danceEnjoy! (And don’t hesitate to write back if you need assistance. I know Tₑχ/LᴬTᴇΧ are beasts, and I’ve also yet to tame them, although I got some common-to-me situations to work.)
MWE:
\documentclass{article}%
\usepackage{graphicx}%
\DeclareGraphicsExtensions{.pdf,.eps,.png,.jpg}%
\begin{document}
\includegraphics[width=\linewidth]{musica1}%
\end{document}
In reply to Tₑχ/LᴬTᴇΧ don’t do SVG… by mirabilos
If you need cropping, you can do it either before or in Tₑχ/LᴬTᴇΧ.
There’s either…
% trim: left down right up
\includegraphics[trim=0cm 25cm 0cm 3cm,clip,width=\linewidth]{musica1}%
… or…
% bb: lower left, upper right; from the lower left corner of the unscaled image
\includegraphics[bb=0cm 20cm 21cm 26cm,clip,width=\linewidth]{musica1}%
… but the units are a bit hard to figure out (neither of these examples worked correctly for me).
bb
normally takes bigpoints (1/72ᵗʰ inch), addingcm
seems to work, but the input data is wrong because these are relative to the PostScript bounding box of the graphics file, which Inkscape sets from the SVG data.Now MuseScore unfortunately exports with 141.732 pixels per centimetre (ca. 360 dpi) and Inkscape seems to convert based on the pixels…
In reply to If you need cropping, you… by mirabilos
Looking further at this: Inkscape also has DPI conversion, and I got the wrong Inkscape command (fixed by editing) from another project. Investigating…
Update: see below, and perhaps better use PDF export.
In reply to Looking further at this:… by mirabilos
Inkscape’s DPI conversion is just because 0.x read pixel values at 90 dpi while 1.x reads pixel values at 96 dpi.
Unfortunately, MuseScore exports pixel values at 360 dpi, so we still have a problem…
In reply to Inkscape’s DPI conversion is… by mirabilos
I wish you had stated your operating system. I seem to have found a really easy way to postprocess the MuseScore-exported SVG to make it load correctly by specifying the size not in pixels, but the conversion will need either hand-editing or some kind of automating tool, and I can provide a GNU/Linux (or BSD) solution now which may not help Windows® users…
In reply to I wish you had stated your… by mirabilos
Right. If using the screenshot function you can also save as PDF, but if you have to go through SVG for some reason, you can convert the MuseScore-output SVGs to properly sized ones with the following command…
if
xmlstarlet
is installed. I’ve been informed there’s also an xmlstarlet for Windows, and this command probably also works on Windows. On Mac OSX, just do it in a Terminal.The command is idempotent, it only converts _nnnn.nn_
px
to _nnn.nnnnnn_in
in the attributes (width
andheight
) of the top-level SVG tag and leaves theviewport
alone (as must be).In reply to Inkscape’s DPI conversion is… by mirabilos
I wonder if ImageMagick could be helpful here.
In reply to I wonder if ImageMagick… by kuwitt
Nah, that’s also a bitmap tool.
You really want to stay in vector graphics land here, especially with Tₑχ/LᴬTᴇΧ…
In reply to Nah, that’s also a bitmap… by mirabilos
I don't have installed ImageMagick at time and it's a long time ago I needed it (probably at that time as third package for a desktop application ;-).
But if I remember correct it also supports the svg file format and you've some command line option to change the resolution with it (-resample, -density or maybe similar). But I never used it, I'm not familiar with it and I'm not sure if it would work (and if, if it would work with all file formats.)
In reply to I don't have installed… by kuwitt
From Google:
Output SVG - ImageMagick
https://legacy.imagemagick.org › Board index › Users
1 Mar 2017 — ImageMagick is primarily a pixel processor. It can read many vector formats but destroys the vectors and replaces them with pixels. Although it ...
So, no, it does not support vector formats, except as input for rasterisation, and even then…
How to convert a SVG to a PNG with ImageMagick? - Stack ...
https://stackoverflow.com › questions › how-to-convert...
19 answers
25 Sep 2014 — I haven't been able to get good results from ImageMagick in this instance, but Inkscape does a nice job of scaling an SVG on Linux and ...
… it doesn’t do a good job at that.
In reply to Tₑχ/LᴬTᴇΧ don’t do SVG… by mirabilos
Also there's lots of tools in linux to manipulate PDFs. As an example these pop up from my commandline.
pdf180 pdf2svg pdfbook2 pdfetex pdfinfo pdfjam-slides6up pdfnup pdfsig pdftohtml pdftotext
pdf270 pdf90 pdfclose pdfflip pdfjam pdfjoin pdfopen pdftex pdftoppm pdfunite
pdf2dsc pdfatfi pdfcrop pdffonts pdfjam-pocketmod pdflatex pdfpun pdftk pdftops pdfxup
pdf2ps pdfbook pdfdetach pdfimages pdfjam-slides3up pdflatexpicscale pdfseparate pdftocairo pdftosrc
Also opening a PDF in gimp can be useful for starting with pretty documents in PDF, converting to what DPI you want, and then grabbing what you want or cropping what you don't want.
In reply to Maybe better use SVG? by Jojo-Schmitz
OK, maybe exporting directly as PDF from MuseScore is better, given the problems with its SVG export. You’ll have to specify the page in Tₑχ/LᴬTᴇΧ then.
musica2.pdf
\DeclareGraphicsExtensions{.pdf,.eps,.png,.jpg}%
like in the other answerpage=
_n_ when including the imagetrim
takes away a specific amount,bb
sets a bounding box)MWE, using equivalent values for
trim
andbb
so the output is the same for a DIN ISO A4 (21x29.7 cm) page (so you can do the maths):\documentclass{article}%
\usepackage{graphicx}%
\DeclareGraphicsExtensions{.pdf,.eps,.png,.jpg}%
\begin{document}
with trim:
% trim: left down right up
\includegraphics[page=2,trim=0cm 20cm 0cm 3.7cm,clip,width=\linewidth]{musica2}%
\newpage
with bb:
% bb: lower left, upper right; from the lower left corner of the unscaled image
\includegraphics[page=2,bb=0cm 20cm 21cm 26cm,clip,width=\linewidth]{musica2}%
\end{document}
In reply to Maybe better use SVG? by Jojo-Schmitz
Given https://musescore.com/groups/improving-musescore-com/discuss/5149436#co… one really must not use MuseScore’s SVG export unless they positively know it works for their situations.
So, best use PDF export and then “cut that to size”.
If you're always using the same page width and a full system, then look at using the image capture tool: https://musescore.org/en/handbook/image-capture
You can save your capture frame size, so it always uses the same size. But (as mentioned by Jojo) you can also use it to save in the SVG format, making your image pretty much lossless in quality.
In reply to If you're always using the… by jeetee
Best to save as PDF, which Tₑχ/LᴬTᴇΧ can use directly (see above).
There’s also a tool called
pdfcrop
, part oftexlive-extra-utils
(albeit without a manual page), which can automatically crop the background away from all PDF files, so you can that in combination with the\includegraphics[…]{name}%
parameters to scale things to the correct size without any pixel artefacts.Btw. a more cumbersome way, there seems to exist a limited MusicXml to MusixTex converter: https://mx2mt.ulmus.cz/.
Another option is to use ImageMagick to trim the white space from your images, that's what I have done in the past. We also implemented at one time a command line option for MuseScore to do this, but I'm not sure how well that works currently - I'm guessing it hasn't been tested in years.
Since I only need small bits of music at a time, I use "EasyABC" to make them and then the "abc package" in LaTeX to include them. Having both EasyABC and TexShop running at the same time, I can get the music the way I want it in EasyABC, save it as a "xxx.abc" file, and then use "\abcinput{xxx}" to bring it into my LaTeX document. If I wanted to have whole pages of music in my LaTeX document, I'd just make a PDF of them and then use the "pdfpages package" to put them in where I wanted them.
The optimum would be to have your score parts in Lilypond and include them in your LaTex document.
In reply to The optimum would be to have… by Rotaton-e
That ⓐ kinda defeats the purpose of having MuseScore-format scores and ⓑ will look visually different, though…
In Latex you can use the Musixtex package for music book. And also there are many tools to translate MusicXML from Musescore to Musixtex such:
https://mx2mt.ulmus.cz
In reply to In Latex you can use the… by abravov
That’s a great tool to have… iff the limitations are acceptable:
> This converter is primary used to transfer songs of Falešné společenstvo from Mozart music processor to MusixTeX typesetting notation via small subset of MusicXML 3.0 format.
It also has the same issue of the music losing the Mu͒seScore visual design. Again, that may or may not be okay, depending on the use cases.