emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] (v6) [PATCH] New feature: Use dvisvgm to preview latex formular


From: tumashu
Subject: Re: [O] (v6) [PATCH] New feature: Use dvisvgm to preview latex formular
Date: Tue, 17 May 2016 06:17:26 +0800 (CST)

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" <address@hidden> 写道:
>Hello,
>
>"Feng Shu" <address@hidden> 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 <address@hidden>
>> 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} address@hidden are respectively available at
>> address@hidden://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

reply via email to

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