emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] General advice beyond Org


From: Adonay Felipe Nogueira
Subject: Re: [O] General advice beyond Org
Date: Tue, 5 Jun 2018 16:52:06 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Icedove/52.8.0

Just an update to let you know that I decided to migrate from
Org-mode+LaTeX to ODF-and-related, particularly because of LPPL+GPL
incompatibility, caused by LaTeX and related projects and because
ODF-and-related are easier for the other people to participate and see
the changes (no need to compile a .pdf nor to download 4 GiB of software).

ODF 1.2 (which is used by default at least in LibreOffice 5) is good and
offers many features similar to Org-mode, including adding files to each
other, interacting with spreadsheets (look for "relative DDE link"), and
also offers bibliography/reference manageemnt, along many other things.

Although I do want to point out that you might want to go to View ->
Disable "Show figures", so that LibreOffice Writer .odt documents are
more editable and less slow.

Also, note that you must recommend people to use LibreOffice to open the
files. Microsoft says to have support, but it's not excellent.

You may also want to import other .odt/.rtf/.doc/.docx files inside the
main one. The tricks are that if you do so using "Insert" -> "Section"
and tick "Link", the inserted section will use the main document's
styles, not their own. Besides, for these files, since they *do* have
notion of what is a "page break", then they will inevitably start in the
next page. Also, inserting them this way may replace or add document
metadata/properties (look in "File" -> "Properties"). at the same time,
some files that you want to add are actually drawings made in
LibreOffice Draw. In all the cases you might want to keep their own
styling. To do this export them to .pdf.

I use this:

------------------------------------------------------------------------
# Please close any running LibreOffice, or `soffice' silently fails.
# No need to specify target file name.
while read each_file
do
  soffice --headless \
        -convert-to pdf \
        "${each_file}"
done <<end_of_list
Preserve styles.docx
Contract.doc
Multi-page document with spaces in name.odt
Drawing.odg
end_of_list
------------------------------------------------------------------------

After this, if you happen to need to import these .pdf files into your
document, use ImageMagick's `convert' command to do the conversion to
.png. For example:

------------------------------------------------------------------------
# `-units' and `-density' are important to be set before .pdf input
# according to what I will do, otherwise there will be loss of quality.
while read pdf_file
do
  convert -units PixelsPerInch \
        -density 300 \
        "${pdf_file}" \
        "$(echo "${pdf_file}" | sed 's/\.pdf$/.png/g')"
done <<end_of_list
Preserve styles.pdf
Multi-page document with spaces in name.pdf
Drawing.pdf
end_of_list
------------------------------------------------------------------------

This will take care of multi-page .pdfs, since the .png files will be
like "Original name-0.png", "Original name-1.png", "Original
name-2.png", and so on. Zero (0) is the first page.

After this conversion, go to the main document, "Insert" ->
"Figure"/"image", tick the box that has "Link" and select the image that
you want to insert. Do this for each .png image.

The "link" options are important so that the main document picks any
change made to the .png image, otherwise LibreOffice will insert the
entire image in the .odt, which will also make it more heavier to attach
in e-mails (but requires the other person to also have the linked file
in the same place).

A caveat of the manual .png insertion is that if a .pdf happens to have
more or less pages than the last conversion to .png, then you will need
to add or delete the related links and their corresponding figures in
the main .odt file. If someone has better solution please share.

Additionally, one can't do "Insert" -> "OLE Object" to insert .odg or
.ods files because these *cannot* break across pages, and don't look
good when printing. This OLE feature wasn't made for printing purpose,
but to facilitate editing without leaving the same program. If I recall
correctly, it's a Microsoft kludge.

As for tabular/table results produced by R, use and abuse of
`write.csv'. Besides, make R output graphics to a .png image (use the
`png' command/device). For all of this, write an .R/.r file and use
Rscript to run it.

The R-produced .png files can be inserted in the main .odt document I
described earlier, no need to repeat the explanation. What you need to
tweak in the `png' R command/device is the `pointsize' and `res'
arguments. Something like this would do:

------------------------------------------------------------------------
## The variables are here just for explanation.

## The standard DPI/`res' of the `png' command/device.
R_img_dpi <- 72

## The standard pointsize of the `png' command/device.
R_pointsize <- 12

## The new DPI/`res' of our image, to make things sharp.
## Just changing `width' or `height' isn't enough.
sharp_img_dpi <- 90

png(file="Plot.png",
        height = 768,
        pointsize = R_pointsize * sharp_img_dpi / R_img_dpi,
        res = sharp_img_dpi,
        width = 1024)

plot(something)
## ... or output some graphic.

## Close/save the .png image.
dev.off()
------------------------------------------------------------------------

Now you ask, how to insert the .csv files in the main .odt document as
tables in a dynamic way (such that if the .csv contents are changed by a
external application, LibreOffice picks the modifocation)?

To partially answer that question, I suggest you to make a new .ods
spreadsheet set/document, and for each .csv, use "Spreadsheet" ->
"Insert spreadsheet from file", select the .csv, enable/tick "Link",
save the .ods. With that done, go to the spreadsheet/tab in LibreOffice
Calc that you want to insert in your main .odt, click on the square
between the column name A and which is above row name 1 (this will
select the entire spreadsheet), copy (Ctrl + C), and Ctrl + Shift + V in
the .odt, select "DDE link".

To style the table, do it in the .odt document, not in the .ods
spreadsheet. Particularly, if you want to make tables with consistent
formating, make the first example table according to your needs then use
the "Table" -> "Style and formating" -> "Add" option to make that
formatting into a new table style. Note however that applying this to
other tables doesn't establish a "style" relationship as is done in the
case of other elements in LibreOffice, so I cannot expect every "Black
1"-styled table to change if I ever update/remake the "Black 1" table
style, so my advice is that these styles deal with display of
tables/cells/rows/columns themselves, not their contents/text. For these
you are better off changing the "Table content" and "Table
title/heading" paragraph styles.

Another caveat of this method is that the DDE column/row references are
absolute ("take from 1 to 3") and as far as I know there is no way to
say "take the entire spreadsheet even if new columns/rows are added".

Again, if someone has a better method that addresses both caveats,
please share.

Finally, there is a known bug[1] in LibreOffice Writer in which DDE
links from Calc .ods files are inserted referring to the absolute path
of the file. So after doing the "Ctrl + Shift + V, select 'DDE link'",
go to "Edit" -> "Links", double-click in the corresponding "soffice"
link to the .ods file, and in "File" field, and change that to relative
path, inserting "file:./" at the start, like so:

Old path: /home/adfeno/Docs/Work/Spreadsheets in the same directory.ods
New path: file:./Spreadsheets in the same directory.ods

Or if the spreadsheets are in some parent directory, use "file:../",
like so:

Old path: /home/adfeno/Docs/Spreadsheets in parent directory.ods
New path: file:../Spreadsheets in parent directory.ods

And so on for traversing to outer directories:

Old path: /home/adfeno/Docs/Contract/Spreadsheets in contract.ods
New path: file:../Contract/Spreadsheets in contract.ods

Similarly:

Old path: /home/adfeno/Spreadsheets at home.ods
New path: file:../../Spreadsheets at home.ods


All in all, the command-line steps are great because you can append
these in the main .odt itself (to be printed verbatim) using "Insert" ->
"Section", and since they are plain text files, it won't make the text
start in new page (so you can write a section title before them).

Happy hacking! :D


[1] https://bugs.documentfoundation.org/show_bug.cgi?id=47223

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]