emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Rasmus <rasmus@gmx.us>
Cc: emacs-orgmode@gnu.org
Subject: Re: [patch, ox-latex] captions and latex-environments
Date: Sat, 18 Mar 2017 10:44:39 +0100	[thread overview]
Message-ID: <87a88kdtvz.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <874lystfyh.fsf@gmx.us> (rasmus@gmx.us's message of "Fri, 17 Mar 2017 10:23:02 +0100")

Hello,

Rasmus <rasmus@gmx.us> writes:

>> Since environments do not necessary start with \begin{...}, I think the
>> following is better
>>
>>   (and (string-match ...)
>>        (match-string ...))
>
> Don't the element `latex-environment' always start \begin{.}?
> Cf. org-element--latex-begin-environment.

At the moment, they do, but I have a patch somewhere to make "\[...\]"
an element instead of an object (e.g., to avoid filling it). It was
accepted, but it some similar change could happen. I'm just suggesting
to make it more robust right from the start.

> Another danger is that someone writes something like,
>
>     \begin{center}
>     \begin{table}
>     ...

You can start the regexp with "\\`[ \t]*..."

> Longtable in an omission, but would have been matched. For some reason
> I thought tabu was no longer supported. Browsing the tabu CTAN page
> there’s links to all sorts of exotic table packages, like "stabular",
> "bigtabular", and "supertabular". I wonder if it’s enough to match the
> ones supported by Org by default, or whether it would be better to
> have it as a defvar that could be hacked if necessary?

tabu/longtabu are supported by Org by default. We could make the list
a defconst anyway.

> I have attached the patch with the changes again and added a changelog
> entry.  I am not sure this needs to be documented, but I’m happy to
> include a couple lines somewhere.

I think the entry in ORG-NEWS is enough.

> +(defun org-latex--environment-type (latex-environment)
> +  "Return the TYPE of LATEX-ENVIRONMENT.
> +
> +The TYPE is determined from the actual latex environment, and
> +could be a member of `org-latex-caption-above' or `math'."
> +  (let* ((value (org-remove-indentation
> +		 (org-element-property :value latex-environment)))
> +	 (env (or (and (string-match "\\\\begin{\\([A-Za-z0-9*]+\\)}" value)
> +		       (match-string 1 value)) "")))

For clarity, "" should be indented at the same level as (and ...).

> +    (cond
> +     ((string-match-p org-latex-math-environments-re value) 'math)
> +     ((string-match-p
> +       (regexp-opt '("table" "longtable" "tabular" "tabu" "longtabu")) env)

Nitpick: you could wrap the above into `eval-when-compile' for a small
optimization.

> +      'table)
> +     ((string-match-p "figure" env) 'image)
> +     ((or (string-match-p "\\(\\(lst\\)?listing\\|verbatim\\|minted\\)" env)
> +	  (string-match-p
> +	   (regexp-opt
> +	    (mapcar (lambda (str)
> +		      (let ((s (cadr str)))
> +			(if (string-match latex-begin-re s)

You removed `latex-begin-re' binding so this is going to fail.

> +			    (match-string 2 s)
> +			  s)))
> +		    org-latex-custom-lang-environments))

I'm not sure it is necessary. AFAIU,
`org-latex-custom-lang-environments' already provides a way to insert
captions.  The matching process above seems fragile.

Thank you.

Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2017-03-18  9:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16 12:02 [patch, ox-latex] captions and latex-environments Rasmus
2017-03-16 12:09 ` Rasmus
2017-03-17  7:22   ` Nicolas Goaziou
2017-03-17  9:23     ` Rasmus
2017-03-18  9:44       ` Nicolas Goaziou [this message]
2017-03-20 14:34         ` Rasmus
2017-03-23 16:17           ` Nicolas Goaziou
2017-03-24 16:25             ` Rasmus
2017-03-27 12:02               ` Nicolas Goaziou
2017-03-27 12:30                 ` Rasmus

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a88kdtvz.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=rasmus@gmx.us \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).