From: tumashu <tumashu@163.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: orgmode-devel <emacs-orgmode@gnu.org>
Subject: Re: (v6) [PATCH] New feature: Use dvisvgm to preview latex formular
Date: Tue, 17 May 2016 06:17:26 +0800 (CST) [thread overview]
Message-ID: <135d32f0.6dc.154bba5322d.Coremail.tumashu@163.com> (raw)
In-Reply-To: <87k2itu2h2.fsf@saiph.selenimh>
i see your mean, i think org-compile-file can do more thing, for example: handle dvipng or dvisvgm,
what i need to know is the different of call-process and run shell command. can we use run shell command instead of call-process in converting dvi to png?
special string need to do more work, i think.
--
发自我的网易邮箱手机智能版
在 2016-05-17 05:17:45,"Nicolas Goaziou" <mail@nicolasgoaziou.fr> 写道:
>Hello,
>
>"Feng Shu" <tumashu@163.com> writes:
>
>> This is my modified patch (v6), fix the problems you stated. please review
>> again, thank!
>
>Thank you. Comments follow.
>
>> From 29760e5c5876fb6b772f7a6004b7160bc06efba8 Mon Sep 17 00:00:00 2001
>> From: Feng Shu <tumashu@163.com>
>> Date: Sat, 14 May 2016 22:42:53 +0800
>> Subject: [PATCH] New feature: Use dvisvgm to preview latex formular
>>
>> * ox-latex.el (org-latex-pdf-process): org-latex-pdf-process can be a
>> configure generator (a plist with :generator keyword).
>> (org-latex-preview-process): new variable, which is used to process
>> latex snippet.
>> (org-latex-compile): Add a new optional argument: extra-info.
>
>As discussed in another message, I don't think we should mess with
>`org-latex-compile'. Instead, we could factor out the needed part in
>`org-latex-compile' and make it a generic function. Then we can
>introduce a new function to specifically handle previewing related
>compilation.
>
>Note that I'm not asking you to implement the factoring out part in your
>patch, but to tell me if the following would fulfill your needs for
>`org-create-formula-image'. I'm sending its docstring again.
>
> (defun org-compile-file (source process extension &optional spec log-buffer)
> "Compile a SOURCE file using PROCESS.
>
> PROCESS is either a function or a list of shell commands, as
> strings.
>
> If PROCESS is a function, it is called with a single argument:
> SOURCE file. It must create a file with the same base name and
> directory as SOURCE, but using extension.
>
> If it is a list of commands, each of them is called using
> `shell-command'. By default, in each command, %b, %f and %o are
> replaced, respectively, with SOURCE base name, SOURCE full name
> and SOURCE directory. It is possible, however, to use different
> place-holders by specifying them in optional argument SPEC. In
> this case, SPEC should be an alist (STRING REPLACEMENT-STRING).
>
> When PROCESS is a list of commands, optional argument LOG-BUFFER
> can be set to a buffer or a buffer name. `shell-command' then
> uses it as an output buffer, which may be used for collecting
> errors.
>
> `default-directory' is set to SOURCE directory during the whole
> process.
>
> Generated file is expected to use the same directory and base
> name as SOURCE, and end with EXTENSION. Return its filename or
> raise an error if it wasn't generated upon executing PROCESS."
> ...)
>
>
>> +If you have a working @LaTeX{} installation and @file{dvipng}, @file{dvisvgm}
>> +or @file{convert} installed@footnote{These are respectively available at
>> +@url{http://sourceforge.net/projects/dvipng/}, @url{http://dvisvgm.bplaced.net/}
>> +and from the @file{imagemagick} suite. Choose the converter by setting the variable
>
>You need to use two spaces to separate sentences.
>
>> +(defcustom org-latex-to-image-backends
>
>You could remove it `org-preview-latex-backends' since it doesn't belong
>to the "org-latex" namespace.
>
>> +dvisvgm Process the LaTeX fragments to dvi/xdv file, then convert
>> + dvi/xdv files to svg files using dvipng.
>
>You probably mean "using dvisvgm".
>
>> +Org mode can use some external commands to generate TeX snippet's image for
>> +previewing or inserting into HTML files, e.g. dvipng, dvisvgm or imagemagick
>> +this variable tells `org-create-formula-image' how to use external commands.
>
>or imagemagick. This variable tells...
>
>> + :class symbol, this setting may be useful in future.
>
>Meanwhile, I suggest to remove it, unless you have a clear plan in mind.
>
>> + :name string, the backend's name.
>> + :programs list of strings, required programs.
>> + :message string, message it when required program can't be found.
>
>required programs
>
>> + :color symbol, if set to `latex', LaTeX \"xcolor\" macro is used
>> + to deal with background and foreground color of image,
>> + if set to `divpng', dvipng style background and foregroud color
>> + format will be generated, you should use them in command options
>> + with special string: \"%fg\"% and \"%bg%\".
>
>are generated; you should used them in ... with special strings: ...
>
>> + :size-adjust cons of numbers, the car element is used to adjust latex image
>> + size showed in buffer and the cdr element is for html file.
>> + this option is only useful for backend developers, user
>> + should use variable `org-format-latex-options' instead.
>
>This option... users...
>
>> + :org-latex-compile boolean, when non-nil, `org-create-formula-image' uses
>> + `org-latex-compile' to compile tex file, otherwise, you need
>> + to set latex command in `:commands' option.
>> + :need-clean list of strings, files matched are to be cleaned up once the
>> + image is generated.
>
>Is it :need-clean or :post-clean? A back-end uses the former, the others
>the latter.
>
>> + :commands list, the commands setting, the following special strings,
>> + will be replaced to according value before commands called.
>> +
>> + 1. %fg% foreground
>> + 2. %bg% background
>> + 3. %dpi% dpi, which used to adjust image size by
>> + some backend's command.
>
>which is used
>
>> + 4. %scale% the image size scale ratio, which used to
>> + adjust image size by some backend's command.
>
>which is used
>
>> + For example, \"%temp-dir%/test\" may be replaced to \"/tmp/test\"
>> + in linux."
>
>Again, please drop "in linux".
>
>> + :group 'org-latex
>> + :version "25.1"
>> + :type '(alist :tag "LaTeX to image backends"
>> + :value-type (plist)))
>
>This can work, but will need to be refined for a nice Customize
>interface.
>
>> (org-in-regexp
>> "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
>>
>> + (when (and overlays (memq processing-type
>> + (mapcar #'car org-latex-to-image-backends)))
>
>(memq processing-type ...) => (assq processing-type org-latex-to-image-backends)
>
>> @@ -19148,11 +19242,14 @@ Some of the options can be changed using the variable
>> (if (string= (match-string 0 value) "$$")
>> (insert "\\[" (substring value 2 -2) "\\]")
>> (insert "\\(" (substring value 1 -1) "\\)"))))
>> - ((dvipng imagemagick)
>> + ((member processing-type
>> + (mapcar #'car org-latex-to-image-backends))
>
>Ditto.
>
>> + (let* ((type (or type 'dvipng))
>> + (backend-info
>> + (cdr (assq type org-latex-to-image-backends)))
>> + (programs (plist-get backend-info :programs))
>
>(cons "latex" (plist-get backend-info :programs))
>
>so you can avoid duplicating checks later. Up to you.
>
>> + (error-message (plist-get backend-info :message))
>> + (color-style (plist-get backend-info :color))
>> + (input-type (plist-get backend-info :input))
>> + (output-type (plist-get backend-info :output))
>> + (post-clean
>> + (delete-dups `(,@(plist-get backend-info :post-clean)
>
>Isn't it :need-clean?
>
>> + ".dvi" ".xdv" ".tex" ".aux" ".log"
>> + ".svg" ".png" ".jpg" ".jpeg" ".out")))
>
>Why do you force other types since they are already provided by preview
>image back-ends. You could do instead
>
>(or (plist-get backend-info :need-clean)
> '(".dvi" ...))
>
>> - (case processing-type
>> - ((t mathjax)
>> + (cond
>> + ((member processing-type '(t mathjax))
>> (org-html-format-latex latex-frag 'mathjax info))
>> - ((dvipng imagemagick)
>> + ((member processing-type
>> + (mapcar #'car org-latex-to-image-backends))
>
>See above.
>
>> (let ((formula-link
>> (org-html-format-latex latex-frag processing-type info)))
>> (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
>> @@ -2819,10 +2823,10 @@ CONTENTS is nil. INFO is a plist holding contextual information."
>> CONTENTS is nil. INFO is a plist holding contextual information."
>> (let ((latex-frag (org-element-property :value latex-fragment))
>> (processing-type (plist-get info :with-latex)))
>> - (case processing-type
>> - ((t mathjax)
>> + (cond
>> + ((member processing-type '(t mathjax))
>> (org-html-format-latex latex-frag 'mathjax info))
>> - ((dvipng imagemagick)
>> + ((member processing-type (mapcar #'car org-latex-to-image-backends))
>
>Ditto.
>
>> (let ((formula-link
>> (org-html-format-latex latex-frag processing-type info)))
>> (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
>> diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
>> index 7fa68c5..2dddb5e 100644
>> --- a/lisp/ox-latex.el
>> +++ b/lisp/ox-latex.el
>> @@ -1119,6 +1119,24 @@ A better approach is to use a compiler suit such as `latexmk'."
>> :version "25.1"
>> :package-version '(Org . "9.0"))
>>
>> +(defcustom org-latex-preview-process
>
>I suggest to rename it `org-preview-latex-process' and move it to
>"org.el".
>
>> + '("latex -interaction nonstopmode -output-directory %o %f")
>> + "Commands to process a LaTeX formula snippet to dvi, xdv or pdf file,
>> +which will be convert to image for previewing or inserting HTML file.
>
>The first line should be a sentence on its own. Maybe
>
>Commands to process a LaTeX snippet to dvi, xdv, or pdf.
>The produced file can be converted to an image and previewed in the
>buffer or inserted in an HTML file.
>
>> + :group 'org-export-pdf
>> + :type '(choice
>> + (repeat :tag "Shell command sequence"
>> + (string :tag "Shell command"))
>> + (const :tag "Use other latex command"
>> + ("%latex -interaction nonstopmode -output-directory %o %f"))
>> + (function)))
>
>Note that there is no requirement for this variable to mimic
>`org-latex-pdf-process'. In particular, the function could accept three
>arguments (texfile, snippet and extra info) bypassing the need for
>the :generator trick altogether.
>
>
>Regards,
>
>--
>Nicolas Goaziou
next prev parent reply other threads:[~2016-05-16 22:17 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-14 6:30 [PATCH] New feature: Use dvisvgm to preview latex formular Feng Shu
2016-05-14 8:47 ` numbchild
2016-05-14 14:56 ` Feng Shu
2016-05-15 2:27 ` Feng Shu
2016-05-15 6:02 ` (version 3) " Feng Shu
2016-05-15 12:14 ` Feng Shu
2016-05-15 22:32 ` Nicolas Goaziou
2016-05-16 5:32 ` Feng Shu
2016-05-16 13:18 ` Nicolas Goaziou
2016-05-16 15:06 ` tumashu
2016-05-16 5:33 ` Feng Shu
2016-05-16 13:19 ` Nicolas Goaziou
2016-05-16 12:05 ` (v6) " Feng Shu
2016-05-16 21:17 ` Nicolas Goaziou
2016-05-16 22:17 ` tumashu [this message]
2016-05-17 1:15 ` tumashu
2016-05-18 6:30 ` (V8) " Feng Shu
2016-05-19 8:22 ` Nicolas Goaziou
2016-05-19 9:18 ` tumashu
2016-05-19 10:32 ` Nicolas Goaziou
2016-05-19 14:01 ` (V9) " Feng Shu
2016-05-21 9:38 ` Nicolas Goaziou
2016-05-21 12:22 ` Feng Shu
2016-05-21 13:35 ` Rasmus
2016-05-15 12:16 ` (version 4) " Feng Shu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=135d32f0.6dc.154bba5322d.Coremail.tumashu@163.com \
--to=tumashu@163.com \
--cc=emacs-orgmode@gnu.org \
--cc=mail@nicolasgoaziou.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.