emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] [patch][ox-latex] context-aware subscript


From: Rasmus
Subject: Re: [O] [patch][ox-latex] context-aware subscript
Date: Sat, 31 Aug 2013 15:59:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hi,

> Thanks for the patch. Here are a few comments.

Thanks for the comments.

>> filter replace all   & $\beta_{\text{}}$   & \texttimes{}$_{\text{}}$   \\
>
> We might be able to handle it more nicely, i.e. by skipping \text when
> contents are empty.

Right, these should be removed due to spacing issues, it seems.
However, in this case the change is induced by a filter.  As such, Ox
doesn't know the final output when in the subscript function.  It's
not easy to predict the outcome of a filter before it's been applied.

What I do in the patch is that I apply the filters within the
function.  I don't like this approach as the doc says that filters are
applied ex post so it seems like cheating...  Also, filters using a
regexp with "\text{whatever}" wouldn't work.

So I'm not too optimistic about this particular apporach.

>> +    (prev (org-export-get-previous-element entity info))
>> +    (next (org-export-get-next-element entity info))
>> +    (no-post-blanks-p (= (or (org-element-property :post-blank entity) 1) 
>> 0))
>> +    (no-pre-blanks-p (= (or (org-element-property :post-blank
>> +                                               
>> (org-export-get-previous-element
>> +                                                entity info)) 1) 0))
>
> A nil :post-blank property means 0, not 1. Also, you don't re-use PREV
> in NO-PRE-BLANKS-P.

Right.  I wanted to check for the case where there is no next/previous
element.  But I was wrong.  Thanks.

>> +    (scripts '(subscript superscript)))
>> +    (if (not (org-element-property :latex-math-p entity)) ent
>> +      (concat
>> +       (if (and no-pre-blanks-p
>> +            (memq (org-element-type prev) scripts)
>> +            (not (eq (org-export-data prev info) "")))
>> +       "" "$")
>> +       ent
>> +       (if (and no-post-blanks-p
>> +            (memq (org-element-type next) scripts)
>> +            (not (eq (org-export-data next info) "")))
>> +       "" "$")))))
>
> I think this is problematic: if an entity needs to export both the
> previous and the next object, what happens when we have two consecutive
> entities? An infloop?

I agree, but I haven't been able to cause any nasty behavior. I've
probably neglected some case.  These works fine

  1. \alpha\beta_t : \alpha is not a subscript
  2. \alpha\beta_\xi\nu : runs OK recursively. 

On 2.: on my system I've tried with many entities (around 500).  It
works, but obviously it's slow due to the recursiveness.  This is very
nasty.  I don't know if some other mechanism can be derived, tho. . .


>> +                (not (org-element-property :latex-math-p prev))
>
> Sure, but I'd rather make a stricter check and also test PREV's type.

OK.

–Rasmus


Test file

#+BEGIN_SRC Org
* filters                                                          :noexport:

#+begin_src emacs-lisp
  (defun test-filter (script backend info)
    (when (org-export-derived-backend-p backend 'latex)
      (if  (string-match "a" script) "" script)))

  (defun test-filter2 (script backend info)
    (when (org-export-derived-backend-p backend 'latex)
      (replace-regexp-in-string "zz" "" script)))

  (add-to-list 'org-export-filter-subscript-functions
                 'test-filter)
  (add-to-list 'org-export-filter-subscript-functions
                 'test-filter2)

#+end_src

#+RESULTS:
| test-filter2 | test-filter |

* test 1

|                      | mathp             | text               |
|----------------------+-------------------+--------------------|
| merge maybe          | \alpha\beta_t     | \alpha\times_t     |
| long merge maybe     | \alpha\beta_tv\xi | \alpha\times_tv\xi |
| filter drop          | \alpha\beta_abc   | \alpha\times_abc   |
| filter replace all   | \alpha\beta_zz    | \alpha\times_zz    |
| filter replace parts | \alpha\beta_zz\xi | \alpha\times_zz\xi |
#+END_SRC

Approximate output

                     & mathp                           & text                   
           
=============================================================================================
merge maybe          & $\alpha$$\beta_{\text{t}}$      & 
$\alpha$\texttimes{}$_{\text{t}}$ 
long merge maybe     & $\alpha$$\beta_{\text{tv}\xi}$  & 
$\alpha$\texttimes{}$_{\text{tv}\xi}$
filter drop          & $\alpha$$\beta$                 & $\alpha$\texttimes{}   
           
filter replace all   & $\alpha$$\beta$                 & $\alpha$\texttimes{}   
           
filter replace parts & $\alpha$$\beta_{\xi}$           & 
$\alpha$\texttimes{}$_{\xi}$      

Attachment: 0001-maybe-merge-subscript-and-mathp-entity-with-some-che.patch
Description: Text Data


--
Need more coffee. . .

reply via email to

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