2

So far, I have set org-latex-packages-alist to '(("margin=2cm" "geometry")), but if the geometry-package is explicitly loaded in a document, I get a clash.

I can use \newgeometry{margin=1cm} in the document, but then latex produces errors on different configurations.

Is there a way to set the default margin (ideally through geometry) without clashing with existing configurations in documents?

xeruf
  • 324
  • 1
  • 12
  • I can make a lot of guesses about what you are asking, but it would be better if you explained it. My main question is: if you include `geometry` in the packages alist, why would you explicitly load it again later? – NickD Jun 20 '21 at 01:10
  • Because I want the document to be usable with different emacs configurations, and margins is (in my works) a common thing to change. – xeruf Jun 22 '21 at 17:00
  • What do those different emacs configurations share? How do they differ? If options clash when you use them with `\usepackage`, how about *not* using them that way? You can make `geometry` an always-included package (without any options) and define the class(es) you use to set options in the preamble with `\geometry{margin=2cm}` afterwards (see `org-latex-classes`). If somebody uses `\geometry{margin=10cm}` later, I don't think that causes any clash. Assuming that works, would that answer your question? – NickD Jun 22 '21 at 19:04
  • Basically, I want the document to be usable on someone else's Emacs configuration, or a blank one. Isn't there some load-package-if-not-loaded-yet kinda macro in latex? Edit: Found it, will add it myself – xeruf Jun 22 '21 at 19:45
  • The Org mode document? Or the LaTeX document? The former will need *some* configuration on the Emacs side. The latter will need a TeXLive installation with all of the relevant packages. Neither is self-contained. – NickD Jun 22 '21 at 20:56

2 Answers2

2

Putting this in the document will set a margin regardless of whether the emacs configuration already loads geometry, but it is a bit clunky and not DRY.

#+LATEX_HEADER: \makeatletter \@ifpackageloaded{geometry}{\geometry{margin=2cm}}{\usepackage[margin=2cm]{geometry}} \makeatother

A solution that modifies my configuration rather than the document would be nicer.

xeruf
  • 324
  • 1
  • 12
  • 1
    `org-format-latex-header` is used for fragment I believe, not whole documents. You should check out `org-latex-classes` for whole documents as I pointed out in one of my comments. – NickD Jun 22 '21 at 20:47
2

Found a good solution for my case: The fullpage latex package.

This package sets all 4 margins to be either 1 inch or 1.5 cm, and specifies the page style.

Which is exactly what I needed, while I can still load geometry within the document to override it.

So I added it to my org-latex-packages-alist:

(setq org-latex-packages-alist '(("" "fullpage") ("avoid-all" "widows-and-orphans") ("" "svg"))
xeruf
  • 324
  • 1
  • 12