emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Alain.Cochard@unistra.fr
Cc: Org Mode List <emacs-orgmode@gnu.org>
Subject: Syntax of footnote-definition: can we allow double empty lines inside? (was: Suspected bug: example block in a footnote doesn't fold if starts with 2 blank lines)
Date: Fri, 02 Sep 2022 20:41:57 +0800	[thread overview]
Message-ID: <87mtbilzhm.fsf@localhost> (raw)
In-Reply-To: <25359.21186.842934.778547@gargle.gargle.HOWL>

Alain.Cochard@unistra.fr writes:

> Ihor Radchenko writes on Wed 31 Aug 2022 09:57:
>
>  > This is not a bug. Just unintuitive syntax:
>  > [...]
>  > The important part is: It ends at the next footnote definition,
>  > headline, or after two consecutive empty lines.
>  > 
>  > So, your example is
>  > 
>  > foo[fn:1]
>  > 
>  > <begin footnote-definition>[fn:1] bar
>  > #+begin_example ;; <- this is not considered an example block because no
>  > major org elements can be inside a footnote definition.
>  > 
>  > 
>  > <end footnote-definition after two empty lines>
>  > <begin paragraph>x
>  > #+end_example
>  > <end paragraph>
>
> Thanks a lot for answering.
>
> Is there an official definition for "major org element" ? (I could not
> find anything relevant in the manual.)

Sorry, I actually confused things in attempt to make things more clear.
The official Org syntax defines 2 types of syntax structures:
elements and objects. Elements can be: (1) headings, (2) sections, (3)
greater elements, (4) lesser elements.

Each Org document is a sequence of elements with no gaps in-between.
Objects (e.g. markup) may be separated by plain text and must always be
inside an existing element.

Headings, sections, and greater elements can contain other elements
inside, while lesser elements cannot.

By "major element" I was actually referring to lesser element
(non-object). Not only I was wrong (footnote-definition is a greater
element), but also used a confusing terminology.

You can refer to https://orgmode.org/worg/dev/org-syntax.html for more
detailed info.

> I guess a headline would qualify (and it would not have occurred to me
> to use a headline within a footnote; the manual is clear in that
> respect anyway).
>
> But then a list item would probably qualify as well?  But, as far as I
> can see, lists and footnotes work perfectly well together... (because
> 2 consecutive empty lines also mark the end of a list item?)
>
> Furthermore, as long as there is not more than one empty line in a
> row, blocks also appear to me to work just fine within footnotes,
> including upon latex export, and I use things like the following all
> the time:
>
>    #+LATEX_HEADER: \usepackage{fancyvrb}
>    #+LATEX_HEADER: \VerbatimFootnotes
>    foot[fn:1]
>
>    [fn:1] note 
>    #+begin_src fortran
> 	 print*,"foo"
>    #+end_src
>
> I simply never had to use 2 consecutive empty lines in blocks up to
> now...
>
> So I guess I'll turn my "suspected bug" into a feature request: that
> #+BEGIN ... #+END blocks behave the same way whether they are within a
> footnote or not.

You are right, there is currently no way to have double blank lines
_inside_ footnote definition. This is because Org syntax prohibits
elements inside a greater element to influence the parent boundaries.
Once Org parser encounters ^[fn:...] right after previously parsed
element, it immediately looks forward for (1) next footnote definition
^[fn:...]; (2) headline ^\*+ ; (3) double blank lines; and sets the
footnote definition boundaries accordingly. Unconditionally. No
backtracking is allowed for the performance reasons.

The consequence is inability to have source blocks containing double
blank lines inside a footnote definition.

This is not an easy problem because we need to ensure backwards
compatibility and avoid doing major changes to Org syntax. The best I
can think of is allowing to escape blank lines like #+ and * lines
inside the code blocks with ",". See 12.6 Literal Examples section of
the manual, for example:

#+BEGIN_EXAMPLE
,* I am no real headline
#+END_EXAMPLE

We may add the same for double blank lines

#+BEGIN_EXAMPLE

,* I am no real headline

,
#+END_EXAMPLE

The downside is overly verbose ordinary code blocks. Double blank lines
may not be uncommon in the wild; sprinkling commas around many source
blocks will be ugly.

Alternative ideas are welcome.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


      reply	other threads:[~2022-09-02 12:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30  7:54 Suspected bug: example block in a footnote doesn't fold if starts with 2 blank lines Alain.Cochard
2022-08-31  1:57 ` Ihor Radchenko
2022-08-31 12:23   ` Alain.Cochard
2022-09-02 12:41     ` Ihor Radchenko [this message]

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=87mtbilzhm.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=Alain.Cochard@unistra.fr \
    --cc=emacs-orgmode@gnu.org \
    /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).