From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rob Stewart Subject: Re: Fwd: Is `org-preview-latex-fragment` sensitive to alignment specified by document class options? Date: Sat, 19 Apr 2014 14:02:48 +0100 Message-ID: References: <87mwfus9j8.fsf@alphaville.bos.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WbUvH-0005EK-Of for emacs-orgmode@gnu.org; Sat, 19 Apr 2014 09:03:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WbUvF-000779-Kx for emacs-orgmode@gnu.org; Sat, 19 Apr 2014 09:03:11 -0400 Received: from mail-yh0-x233.google.com ([2607:f8b0:4002:c01::233]:43167) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WbUvF-00076m-FM for emacs-orgmode@gnu.org; Sat, 19 Apr 2014 09:03:09 -0400 Received: by mail-yh0-f51.google.com with SMTP id f10so2244212yha.10 for ; Sat, 19 Apr 2014 06:03:08 -0700 (PDT) In-Reply-To: <87mwfus9j8.fsf@alphaville.bos.redhat.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nick Dokos , emacs-orgmode@gnu.org Hi Nick, Thanks for guiding me to a solution, which was to write write my own defcustom `my-org-format-latex-header`, changing the first line from the definition in org.el to "\\documentclass[fleqn]{article}". This definition I call `my-org-format-latex-header`. I then redefine `org-create-formula--latex-header` to use `my-org-format-latex-header`, as so: --8<---------------cut here---------------start------------->8--- (defcustom my-org-format-latex-header "\\documentclass[fleqn]{article} \\usepackage[usenames]{color} \[PACKAGES] \[DEFAULT-PACKAGES] \\pagestyle{empty} % do not remove % The settings below are copied from fullpage.sty \\setlength{\\textwidth}{\\paperwidth} \\addtolength{\\textwidth}{-3cm} \\setlength{\\oddsidemargin}{1.5cm} \\addtolength{\\oddsidemargin}{-2.54cm} \\setlength{\\evensidemargin}{\\oddsidemargin} \\setlength{\\textheight}{\\paperheight} \\addtolength{\\textheight}{-\\headheight} \\addtolength{\\textheight}{-\\headsep} \\addtolength{\\textheight}{-\\footskip} \\addtolength{\\textheight}{-3cm} \\setlength{\\topmargin}{1.5cm} \\addtolength{\\topmargin}{-2.54cm}" "The document header used for processing LaTeX fragments. It is imperative that this header make sure that no page number appears on the page. The package defined in the variables `org-latex-default-packages-alist' and `org-latex-packages-alist' will either replace the placeholder \"[PACKAGES]\" in this header, or they will be appended." :group 'org-latex :type 'string) (defun org-create-formula--latex-header () "Return LaTeX header appropriate for previewing a LaTeX snippet." (let ((info (org-combine-plists (org-export--get-global-options (org-export-get-backend 'latex)) (org-export--get-inbuffer-options (org-export-get-backend 'latex))))) (org-latex-guess-babel-language (org-latex-guess-inputenc (org-splice-latex-header my-org-format-latex-header org-latex-default-packages-alist org-latex-packages-alist t (plist-get info :latex-header))) info))) --8<---------------cut here---------------end--------------->8--- Now when I call `org-preview-latex-fragment`, the math is correctly rendered in emacs: http://imgur.com/mMrMIE6 My only question is: rather than using `defcustom` to define `my-org-format-latex-header` (hence needing to redefine `org-create-formula--latex-header`, how do I simply override the existing definition for `org-format-latex-header`? A hasty attempt to use setq threw the following backtrace: --8<---------------cut here---------------start------------->8--- Debugger entered--Lisp error: (wrong-type-argument symbolp "The document header used for processing LaTeX fragments. It is imperative that this header make sure that no page number appears on the page. The package defined in the variables `org-latex-default-packages-alist' and `org-latex-packages-alist' will either replace the placeholder \"[PACKAGES]\" in this header, or they will be appended.") (setq org-format-latex-header "\\documentclass[fleqn]{article} .. eval-last-sexp-1(nil) eval-last-sexp(nil) call-interactively(eval-last-sexp nil nil) --8<---------------cut here---------------end--------------->8--- Thanks Nick! -- Rob On 9 April 2014 18:22, Nick Dokos wrote: > Rob Stewart writes: > >> >> I asked the question below a few days ago, about whether >> `org-preview-latex-fragment` is sensitive document class options that >> might affect alignment. I've so far not received feedback, and >> wondered whether there is more information that I could provide, or if >> my question is not interesting to other people :-) >> >> .... >> >> Is there a way to make `org-preview-latex-fragment` sensitive to LaTeX >> class options? I have a simple example to demonstrate where it does >> not: >> >> %%%%%%% #+LaTeX_CLASS: article #+LaTeX_CLASS_OPTIONS: [fleqn] >> #+LATEX_HEADER: \usepackage{amsmath} >> >> \begin{gather} b := (a \oplus s_1) \oplus s_2 \\ e := 0 \\ >> \end{gather} %%%%%%% >> >> If LaTeX is generated for this document with >> `org-latex-export-to-latex`, which is compiled to a PDF with pdflatex, >> the "b :=" and the "e :=" are left aligned i.e. the "b" and "e" are >> vertically aligned. >> >> However, if `org-preview-latex-fragment` is called within emacs, the >> left alignment specified with the `[fleqn]` class option is not >> honoured. Thus, the two lines in the `gather` block are centrally >> aligned, which is the default case for `gather` blocks. >> > > org-preview-latex-image is its own self-contained universe and has very > little in common with latex exporting. In particular, the preview > preamble is generated by calling org-create-formula--latex-header. Try > evaluating a call to the function in your *scratch* buffer and see what > it gives you - I get: > > ,---- > | (org-create-formula--latex-header) > | "\\documentclass{article} > | \\usepackage[usenames]{color} > | % Package minted omitted > | \\usepackage[utf8]{inputenc} > | \\usepackage[T1]{fontenc} > | % Package fixltx2e omitted > | \\usepackage{graphicx} > | % Package longtable omitted > | % Package float omitted > | % Package wrapfig omitted > | % Package rotating omitted > | \\usepackage[normalem]{ulem} > | \\usepackage{amsmath} > | \\usepackage{textcomp} > | \\usepackage{marvosym} > | \\usepackage{wasysym} > | \\usepackage{amssymb} > | % Package hyperref omitted > | \\tolerance=1000 > | \\pagestyle{empty} % do not remove > | % The settings below are copied from fullpage.sty > | \\setlength{\\textwidth}{\\paperwidth} > | \\addtolength{\\textwidth}{-3cm} > | \\setlength{\\oddsidemargin}{1.5cm} > | \\addtolength{\\oddsidemargin}{-2.54cm} > | \\setlength{\\evensidemargin}{\\oddsidemargin} > | \\setlength{\\textheight}{\\paperheight} > | \\addtolength{\\textheight}{-\\headheight} > | \\addtolength{\\textheight}{-\\headsep} > | \\addtolength{\\textheight}{-\\footskip} > | \\addtolength{\\textheight}{-3cm} > | \\setlength{\\topmargin}{1.5cm} > | \\addtolength{\\topmargin}{-2.54cm}" > `---- > > As you can see both the document class and the class options (none) > are hardwired. > > The function looks like this > > ,---- > | (defun org-create-formula--latex-header () > | "Return LaTeX header appropriate for previewing a LaTeX snippet." > | (let ((info (org-combine-plists (org-export--get-global-options > | (org-export-get-backend 'latex)) > | (org-export--get-inbuffer-options > | (org-export-get-backend 'latex))))) > | (org-latex-guess-babel-language > | (org-latex-guess-inputenc > | (org-splice-latex-header > | org-format-latex-header org-latex-default-packages-alist > | org-latex-packages-alist t (plist-get info :latex-header))) > | info))) > `---- > > so in order to add class options you have to redefine the variable > org-format-latex-header. But whatever you set them to, they will be > hardwired: there is no way to propagate a setting from the org > file. > > Nick > > > >