I replaced setup_paper in docutils/writers/odf_odt/__init__.py by:
defsetup_paper(self,root_el):try:dimensions=subprocess.check_output(('paper','--unit pt'),stderr=subprocess.STDOUT)""" Example output of paper --unit pt: A4: 595.276x841.89 pt Letter: 612x792 pt """x=re.split("\w.*: (\d*(\.\d*)*)x(\d*(\.\d*)*) .*",txt)w=float(x[1])h=float(x[3])except(subprocess.CalledProcessError,FileNotFoundError,ValueError):self.document.reporter.info('Cannot use `paper`, defaulting to Letter.')w,h=612,792# default to Letter
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for the report and suggestion.
One problem is, that the "old" paperconf command does not recognize the --unit option.
Maybe we can try the old syntax and processing if the new command fails before falling back to
"letter" or "A4".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The attached patch combines the "old" code with your change suggestion.
"flake8" shows a number of complaints (e.g. variable "txt" never used).
Also, the regexp looks overly complicated and I'd rather use re.search() than re.split().
Did you test the proposed change?
And a test stub. (A proper test would need an independent method to find out if the user has a configured page size and check it is properly retrieved.)
It works for me (i.e. with the "old" libpaper).
Mind, that the behaviour of rst2odt with the new "libpaper" version is similar to the current behaviour on systems without "libpaper/paperconf": the page size defaults to US-Letter and an "info" level message is printed. So it is no complete breakdown.
Also mind, that you must use a custom stylesheet without page size settings to get the page size determined by "paperconf". https://docutils.sourceforge.io/docs/user/odt.html#page-size
The default style sheet (docutils/writers/odf_odt/styles.odt) sets the page size to US Letter. Hence, by default, documents are generated with "US Letter" page size also on systems with a properly working "paperconf" set to A4.
Last edit: Günter Milde 2023-05-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
https://github.com/rrthomas/libpaper/issues/42
The author reported we can use this command instead:
I replaced setup_paper in
docutils/writers/odf_odt/__init__.pyby:Thank you for the report and suggestion.
One problem is, that the "old"
paperconfcommand does not recognize the--unitoption.Maybe we can try the old syntax and processing if the new command fails before falling back to
"letter" or "A4".
Indeed, I forgot to handle the case when we have an "old" paperconf ^^
The attached patch combines the "old" code with your change suggestion.
"flake8" shows a number of complaints (e.g. variable "txt" never used).
Also, the regexp looks overly complicated and I'd rather use re.search() than re.split().
Did you test the proposed change?
And a test stub. (A proper test would need an independent method to find out if the user has a configured page size and check it is properly retrieved.)
It works for me (i.e. with the "old" libpaper).
Last edit: Günter Milde 2023-04-20
Mind, that the behaviour of
rst2odtwith the new "libpaper" version is similar to the current behaviour on systems without "libpaper/paperconf": the page size defaults to US-Letter and an "info" level message is printed. So it is no complete breakdown.Also mind, that you must use a custom stylesheet without page size settings to get the page size determined by "paperconf". https://docutils.sourceforge.io/docs/user/odt.html#page-size
The default style sheet (docutils/writers/odf_odt/styles.odt) sets the page size to US Letter. Hence, by default, documents are generated with "US Letter" page size also on systems with a properly working "paperconf" set to A4.
Last edit: Günter Milde 2023-05-12
Before the proposed patch can be applied to the repo, it needs to be tested on a system with the new paperconf. Waiting for volunteers.