emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
@ 2023-03-03 10:07 Andrea Lazzarini
  2023-03-03 14:44 ` Max Nikulin
  0 siblings, 1 reply; 22+ messages in thread
From: Andrea Lazzarini @ 2023-03-03 10:07 UTC (permalink / raw)
  To: emacs-orgmode


After setting 'org-export-with-footnotes' to 'nil', 
the space following the footnote is removed when exporting (I’ve tested
this with pandoc [docx and html]).

So, given this example:

«Pellentesque dapibus suscipit ligula.[fn:1]  Donec posuere augue in quam.»

The resulting text is:

«Pellentesque dapibus suscipit ligula.Donec posuere augue in quam.»

The only way in which I can get a space in the correct place  is by putting an extra one
before the footnote.


Emacs  : GNU Emacs 28.0.91 (build 1, aarch64-apple-darwin21.2.0, NS appkit-2113.20 Version 12.1 (Build 21C52))
 of 2022-02-06
Package: Org mode version 9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-03 10:07 [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)] Andrea Lazzarini
@ 2023-03-03 14:44 ` Max Nikulin
  2023-03-03 15:47   ` Ihor Radchenko
  0 siblings, 1 reply; 22+ messages in thread
From: Max Nikulin @ 2023-03-03 14:44 UTC (permalink / raw)
  To: Andrea Lazzarini, emacs-orgmode

On 03/03/2023 17:07, Andrea Lazzarini wrote:
> 
> After setting 'org-export-with-footnotes' to 'nil',
> the space following the footnote is removed when exporting (I’ve tested
> this with pandoc [docx and html]).

I am unsure if pandoc is relevant. However the issue exists for ox, e.g. 
ox-latex and ox-html.

> «Pellentesque dapibus suscipit ligula.[fn:1]  Donec posuere augue in quam.»

Self-containing example:

---- 8< ----
#+options: f:nil

Pellentesque dapibus suscipit ligula.[fn::1 ftnt]  Donec posuere augue 
in quam.
---- >8 ----

Confirmed.

A workaround is to either add a zero-width space or use non-breakable 
space (as literal character or as \nbsp{} entity) immediately after 
footnotes.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-03 14:44 ` Max Nikulin
@ 2023-03-03 15:47   ` Ihor Radchenko
  2023-03-03 16:47     ` Max Nikulin
  0 siblings, 1 reply; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-03 15:47 UTC (permalink / raw)
  To: Max Nikulin; +Cc: Andrea Lazzarini, emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> Self-containing example:
>
> ---- 8< ----
> #+options: f:nil
>
> Pellentesque dapibus suscipit ligula.[fn::1 ftnt]  Donec posuere augue 
> in quam.
> ---- >8 ----

This is because spaces after Org syntax objects are considered a part of
those syntax objects.  So, excluding footnote automatically means
excluding spaces after.

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-03 15:47   ` Ihor Radchenko
@ 2023-03-03 16:47     ` Max Nikulin
  2023-03-04 15:43       ` Andrea Lazzarini
  2023-03-05 12:06       ` Ihor Radchenko
  0 siblings, 2 replies; 22+ messages in thread
From: Max Nikulin @ 2023-03-03 16:47 UTC (permalink / raw)
  Cc: Andrea Lazzarini, emacs-orgmode

On 03/03/2023 22:47, Ihor Radchenko wrote:
> Max Nikulin writes:
> 
>> Self-containing example:
>>
>> ---- 8< ----
>> #+options: f:nil
>>
>> Pellentesque dapibus suscipit ligula.[fn::1 ftnt]  Donec posuere augue
>> in quam.
>> ---- >8 ----
> 
> This is because spaces after Org syntax objects are considered a part of
> those syntax objects.  So, excluding footnote automatically means
> excluding spaces after.

In my opinion, the filter removing footnotes should transfer afterspaces 
to preceding objects.



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-03 16:47     ` Max Nikulin
@ 2023-03-04 15:43       ` Andrea Lazzarini
  2023-03-05 12:06       ` Ihor Radchenko
  1 sibling, 0 replies; 22+ messages in thread
From: Andrea Lazzarini @ 2023-03-04 15:43 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

I totally agree with Max Nikulin: wouldn't that be an improvement? That would make things a lot easier for those instances in which you want to put the footnotes back in.

> Il giorno 3 mar 2023, alle ore 17:47, Max Nikulin <manikulin@gmail.com> ha scritto:
> 
> On 03/03/2023 22:47, Ihor Radchenko wrote:
>> Max Nikulin writes:
>>> Self-containing example:
>>> 
>>> ---- 8< ----
>>> #+options: f:nil
>>> 
>>> Pellentesque dapibus suscipit ligula.[fn::1 ftnt]  Donec posuere augue
>>> in quam.
>>> ---- >8 ----
>> This is because spaces after Org syntax objects are considered a part of
>> those syntax objects.  So, excluding footnote automatically means
>> excluding spaces after.
> 
> In my opinion, the filter removing footnotes should transfer afterspaces to preceding objects.
> 



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-03 16:47     ` Max Nikulin
  2023-03-04 15:43       ` Andrea Lazzarini
@ 2023-03-05 12:06       ` Ihor Radchenko
  2023-03-05 12:32         ` Andrea Lazzarini
  1 sibling, 1 reply; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-05 12:06 UTC (permalink / raw)
  To: Max Nikulin; +Cc: Andrea Lazzarini, emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> In my opinion, the filter removing footnotes should transfer afterspaces 
> to preceding objects.

I am not sure.

Consider text like "Pellentesque dapibus suscipit ligula. [fn:1] Donec posuere augue in quam."
with space before the footnote. If we replace the footnote with space,
two spaces will be exported. I am not sure if it is expected.

Also, should we replace footnote with a single space or with the number
of spaces after?

Further, this bug is actually not just about footnotes. The footnotes
are removed in `org-export--prune-tree':

    (if (org-export--skip-p data info selected excluded)
    		      (if (memq type '(table-cell table-row)) (push data ignore)
    			(org-element-extract-element data))

The extracted objects can be latex-fragment, statistics-cookie,
timestamp, and footnote.

Will it be safe to replace all the above with space? Or maybe with
number of spaces equal to :post-blank? Something else?

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-05 12:06       ` Ihor Radchenko
@ 2023-03-05 12:32         ` Andrea Lazzarini
  2023-03-05 12:42           ` Ihor Radchenko
  0 siblings, 1 reply; 22+ messages in thread
From: Andrea Lazzarini @ 2023-03-05 12:32 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Max Nikulin, emacs-orgmode

Consider the fact that I had to put an extra space before the footnote exactly to have a space (not an extra one) in the result.

As you say, couldn't it be replaced with:

> maybe with number of spaces equal to :post-blank ?



> Il giorno 5 mar 2023, alle ore 13:06, Ihor Radchenko <yantar92@posteo.net> ha scritto:
> 
> Max Nikulin <manikulin@gmail.com> writes:
> 
>> In my opinion, the filter removing footnotes should transfer afterspaces 
>> to preceding objects.
> 
> I am not sure.
> 
> Consider text like "Pellentesque dapibus suscipit ligula. [fn:1] Donec posuere augue in quam."
> with space before the footnote. If we replace the footnote with space,
> two spaces will be exported. I am not sure if it is expected.
> 
> Also, should we replace footnote with a single space or with the number
> of spaces after?
> 
> Further, this bug is actually not just about footnotes. The footnotes
> are removed in `org-export--prune-tree':
> 
>    (if (org-export--skip-p data info selected excluded)
>    		      (if (memq type '(table-cell table-row)) (push data ignore)
>    			(org-element-extract-element data))
> 
> The extracted objects can be latex-fragment, statistics-cookie,
> timestamp, and footnote.
> 
> Will it be safe to replace all the above with space? Or maybe with
> number of spaces equal to :post-blank? Something else?
> 
> -- 
> Ihor Radchenko // yantar92,
> 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>



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-05 12:32         ` Andrea Lazzarini
@ 2023-03-05 12:42           ` Ihor Radchenko
  2023-03-05 12:54             ` Andrea Lazzarini
  0 siblings, 1 reply; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-05 12:42 UTC (permalink / raw)
  To: Andrea Lazzarini; +Cc: Max Nikulin, emacs-orgmode


Andrea Lazzarini <andrea.lazzarini1@gmail.com> writes:
> Consider the fact that I had to put an extra space before the footnote exactly to have a space (not an extra one) in the result.
>
> As you say, couldn't it be replaced with:
>
>> maybe with number of spaces equal to :post-blank ?

Sure, but footnotes are expected to have space before in some languages:

 Sentence. [footnote] Another sentence.

Keeping the space after will leave us with _two_ spaces:

 Sentence.  Another sentence.

Not ideal when exporting to, say, ASCII.

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-05 12:42           ` Ihor Radchenko
@ 2023-03-05 12:54             ` Andrea Lazzarini
  2023-03-05 13:01               ` Ihor Radchenko
  0 siblings, 1 reply; 22+ messages in thread
From: Andrea Lazzarini @ 2023-03-05 12:54 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Max Nikulin, emacs-orgmode

If some languages require it and some not, as you correctly say, couldn't the behaviour be customizable? 

> Il giorno 5 mar 2023, alle ore 13:42, Ihor Radchenko <yantar92@posteo.net> ha scritto:
> 
> 
> Andrea Lazzarini <andrea.lazzarini1@gmail.com> writes:
>> Consider the fact that I had to put an extra space before the footnote exactly to have a space (not an extra one) in the result.
>> 
>> As you say, couldn't it be replaced with:
>> 
>>> maybe with number of spaces equal to :post-blank ?
> 
> Sure, but footnotes are expected to have space before in some languages:
> 
> Sentence. [footnote] Another sentence.
> 
> Keeping the space after will leave us with _two_ spaces:
> 
> Sentence.  Another sentence.
> 
> Not ideal when exporting to, say, ASCII.
> 
> -- 
> Ihor Radchenko // yantar92,
> 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>



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-05 12:54             ` Andrea Lazzarini
@ 2023-03-05 13:01               ` Ihor Radchenko
  2023-03-06 12:18                 ` Max Nikulin
  0 siblings, 1 reply; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-05 13:01 UTC (permalink / raw)
  To: Andrea Lazzarini; +Cc: Max Nikulin, emacs-orgmode

Andrea Lazzarini <andrea.lazzarini1@gmail.com> writes:

> If some languages require it and some not, as you correctly say, couldn't the behaviour be customizable? 

Maybe. But we are not only talking about footnotes.
Consider

* Heading [0/1] text

Or

Text with newline\\
[footnote]  more text.

or

Text (parens[footnote] ).

It might be enough to use spaces if and only if there are no preceding
spaces. Or not. One may think of other edge cases.

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-05 13:01               ` Ihor Radchenko
@ 2023-03-06 12:18                 ` Max Nikulin
  2023-03-07 13:59                   ` Ihor Radchenko
  0 siblings, 1 reply; 22+ messages in thread
From: Max Nikulin @ 2023-03-06 12:18 UTC (permalink / raw)
  To: Andrea Lazzarini; +Cc: emacs-orgmode

On 05/03/2023 20:01, Ihor Radchenko wrote:
> Consider
> 
> * Heading [0/1] text
...
> Text with newline\\
> [footnote]  more text.
...
> Text (parens[footnote] ).

I am not convinced that space should be dropped here.

> It might be enough to use spaces if and only if there are no preceding
> spaces. Or not. One may think of other edge cases.

An idea: retain :post-blank having more spaces. Newline > tab, tab = 8 
spaces.

Ihor, could you, please, be more specific concerning languages where 
spaces may be used before footnote marks? I would expect at least 
non-breakable spaces, but they are not stripped currently.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-06 12:18                 ` Max Nikulin
@ 2023-03-07 13:59                   ` Ihor Radchenko
  2023-03-08 15:14                     ` Max Nikulin
  0 siblings, 1 reply; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-07 13:59 UTC (permalink / raw)
  To: Max Nikulin; +Cc: Andrea Lazzarini, emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> On 05/03/2023 20:01, Ihor Radchenko wrote:
>> Consider
>> 
>> * Heading [0/1] text
> ...
>> Text with newline\\
>> [footnote]  more text.
> ...
>> Text (parens[footnote] ).
>
> I am not convinced that space should be dropped here.

I agree about the last example, but what about "Heading [0/1] text"?

>> It might be enough to use spaces if and only if there are no preceding
>> spaces. Or not. One may think of other edge cases.
>
> An idea: retain :post-blank having more spaces. Newline > tab, tab = 8 
> spaces.

May you elaborate about "newline > tab, tab = 8 spaces"?

> Ihor, could you, please, be more specific concerning languages where 
> spaces may be used before footnote marks? I would expect at least 
> non-breakable spaces, but they are not stripped currently.

Well. Not languages per se. (I have none in mind)
I was thinking about various representations of footnotes. In
particular, footnotes in ascii/texinfo export.

However, I now checked what we do about footnotes in Org manual, and we
do not use spaces:

    The summary type.  If specified, the column values for parent nodes
    are computed from the children(1).

So, maybe it is safe to assume that spaces are not commonly used right
before footnote references.

This is only for footnotes though. The code responsible for removing
certain AST objects during export works not just foot footnotes. Unless
there is a strong reason to treat footnotes specially, I'd prefer a more
universal solution of the problem that will work for all kinds of
removed objects.

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-07 13:59                   ` Ihor Radchenko
@ 2023-03-08 15:14                     ` Max Nikulin
  2023-03-09 12:43                       ` Ihor Radchenko
  0 siblings, 1 reply; 22+ messages in thread
From: Max Nikulin @ 2023-03-08 15:14 UTC (permalink / raw)
  To: emacs-orgmode

On 07/03/2023 20:59, Ihor Radchenko wrote:
> I agree about the last example, but what about "Heading [0/1] text"?

Both "Heading" and "[0/1]" have the same :post-blank " ", so when 
stripping the statistics cookie use " " :post-blank for "Heading" 
(retain current value).

> Max Nikulin writes:
>> On 05/03/2023 20:01, Ihor Radchenko wrote:
>>> It might be enough to use spaces if and only if there are no preceding
>>> spaces. Or not. One may think of other edge cases.
>>
>> An idea: retain :post-blank having more spaces. Newline > tab, tab = 8
>> spaces.
> 
> May you elaborate about "newline > tab, tab = 8 spaces"?

Consider your earlier example:

>>> Text with newline\\
>>> [footnote]  more text.

Line-break has :post-blank "\n" that is greater than the "  " 
:post-blank value of the footnote reference, so when dropping the 
footnote retain "\n" from line break.

---- 8< ----
Text   [footnote]
  next line
---- >8 ----

Use "\n " from "[footnote]" because it is greater than "   " that is 
:post-blank of "Text".




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-08 15:14                     ` Max Nikulin
@ 2023-03-09 12:43                       ` Ihor Radchenko
  2023-03-09 15:04                         ` Max Nikulin
  0 siblings, 1 reply; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-09 12:43 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> On 07/03/2023 20:59, Ihor Radchenko wrote:
>> I agree about the last example, but what about "Heading [0/1] text"?
>
> Both "Heading" and "[0/1]" have the same :post-blank " ", so when 
> stripping the statistics cookie use " " :post-blank for "Heading" 
> (retain current value).

Sorry, but we are mis-communicating here.
:post-blank can be either nil or a number of spaces/tabs after object.

Plain strings always have :post-blank nil.
So do line breaks.

>> May you elaborate about "newline > tab, tab = 8 spaces"?
>
> Consider your earlier example:
>
>>>> Text with newline\\
>>>> [footnote]  more text.

Try M-: (pp (org-element-parse-buffer))

----
Text with newline \\
 [fn:1]  more text.
----

You will get

(org-data
 (:begin 1 :contents-begin 1 :contents-end 42 :end 42 :robust-begin 3 :robust-end 40 :post-blank 0 :post-affiliated 1 :path "/tmp/bug.org" :mode org-data :CATEGORY "bug" :granularity nil)
 (section
  (:begin 1 :end 42 :contents-begin 1 :contents-end 42 :robust-begin 1 :robust-end 40 :post-blank 0 :post-affiliated 1 :mode first-section :granularity nil :parent #0)
  (paragraph
   (:begin 1 :end 42 :contents-begin 1 :contents-end 42 :post-blank 0 :post-affiliated 1 :mode top-comment :granularity nil :parent #1)
   #("Text with newline " 0 18
     (:parent #2))
   (line-break
    (:begin 19 :end 22 :post-blank 0 :parent #2))
   #(" " 0 1
     (:parent #2))
   (footnote-reference
    (:label "1" :type standard :begin 23 :end 31 :contents-begin nil :contents-end nil :post-blank 2 :parent #2))
   #("more text.\n" 0 11
     (:parent #2)))))

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-09 12:43                       ` Ihor Radchenko
@ 2023-03-09 15:04                         ` Max Nikulin
  2023-03-10 12:08                           ` Ihor Radchenko
  0 siblings, 1 reply; 22+ messages in thread
From: Max Nikulin @ 2023-03-09 15:04 UTC (permalink / raw)
  To: emacs-orgmode

On 09/03/2023 19:43, Ihor Radchenko wrote:
> Max Nikulin writes:
>> Both "Heading" and "[0/1]" have the same :post-blank " ", so when
>> stripping the statistics cookie use " " :post-blank for "Heading"
>> (retain current value).
> 
> Sorry, but we are mis-communicating here.

No, it just means that I am not familiar enough with org-element structures.

> :post-blank can be either nil or a number of spaces/tabs after object.
> 
> Plain strings always have :post-blank nil.
> So do line breaks.

If preceding object is string than trailing spaces should be taken into 
account instead of :post-blank. If footnote reference or similar object 
has more :post-blank spaces than replace it by string with space 
characters to have footnote's :post-blank in total. Alternatively append 
these spaces to the preceding string.

> ----
> Text with newline \\
>   [fn:1]  more text.
> ----
>     #("Text with newline " 0 18
>       (:parent #2))
>     (line-break
>      (:begin 19 :end 22 :post-blank 0 :parent #2))
>     #(" " 0 1
1 space--^
>     (footnote-reference
>      (:label "1" ... :post-blank 2 :parent #2))
2 spaces---------------------------^
>     #("more text.\n" 0 11

So stripping the footnote use 2 spaces "  " instead of preceding " " or 
add another " " (unsure if 2 adjacent strings may be a problem for 
export backends).

I was imprecise, but I do not see any contradictions.




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-09 15:04                         ` Max Nikulin
@ 2023-03-10 12:08                           ` Ihor Radchenko
  2023-03-10 14:03                             ` Max Nikulin
  0 siblings, 1 reply; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-10 12:08 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

>> Plain strings always have :post-blank nil.
>> So do line breaks.
>
> If preceding object is string than trailing spaces should be taken into 
> account instead of :post-blank. If footnote reference or similar object 
> has more :post-blank spaces than replace it by string with space 
> characters to have footnote's :post-blank in total. Alternatively append 
> these spaces to the preceding string.

Do I understand correctly that you propose the following:

If we have

  [previous object <n1 spaces>][object to be removed <n2 spaces>]

change it to

  [previous object <max(n1,n2) spaces>]

?

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-10 12:08                           ` Ihor Radchenko
@ 2023-03-10 14:03                             ` Max Nikulin
  2023-03-11 10:38                               ` Ihor Radchenko
  0 siblings, 1 reply; 22+ messages in thread
From: Max Nikulin @ 2023-03-10 14:03 UTC (permalink / raw)
  To: emacs-orgmode

On 10/03/2023 19:08, Ihor Radchenko wrote:
> Do I understand correctly that you propose the following:
> 
> If we have
> 
>    [previous object <n1 spaces>][object to be removed <n2 spaces>]
> 
> change it to
> 
>    [previous object <max(n1,n2) spaces>]

Yes, you do.

I expected some complications due to newline characters (not line break 
markup objects), but they are not included in :post-blank and 
represented as "\n" string objects.

Actually there is an issue with newline characters and ox-latex. 
Stripping footnotes splits single paragraphs into 2 ones:

---- >8 ----
#+options: f:nil
First
[fn::foot]
Second
---- 8< ----

So newlines should be handled somehow. Earlier I faced a similar issue with
@@comment:export snippets@@
and ox-latex.



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-10 14:03                             ` Max Nikulin
@ 2023-03-11 10:38                               ` Ihor Radchenko
  2023-03-13 15:17                                 ` Max Nikulin
  2023-03-27 14:16                                 ` Ihor Radchenko
  0 siblings, 2 replies; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-11 10:38 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 929 bytes --]

Max Nikulin <manikulin@gmail.com> writes:

>>    [previous object <max(n1,n2) spaces>]
>
> Yes, you do.
>
> I expected some complications due to newline characters (not line break 
> markup objects), but they are not included in :post-blank and 
> represented as "\n" string objects.

Newlines are tricky. They may or may not be significant.
For example, in CJK paragraphs, newlines are to be stripped.

I think that a reasonable thing to do could be not adding newlines if
the previous object is a plain string ending with a newline.

> Actually there is an issue with newline characters and ox-latex. 
> Stripping footnotes splits single paragraphs into 2 ones:
>
> ---- >8 ----
> #+options: f:nil
> First
> [fn::foot]
> Second
> ---- 8< ----
>
> So newlines should be handled somehow. Earlier I faced a similar issue with
> @@comment:export snippets@@
> and ox-latex.

This is latex-specific.
See the attached tentative fix.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-latex-paragraph-Ensure-that-paragraphs-are-not-s.patch --]
[-- Type: text/x-patch, Size: 1455 bytes --]

From 92800f77ea6389b531c4d96cc4b32ed5557aa47a Mon Sep 17 00:00:00 2001
Message-Id: <92800f77ea6389b531c4d96cc4b32ed5557aa47a.1678531087.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sat, 11 Mar 2023 11:34:45 +0100
Subject: [PATCH] org-latex-paragraph: Ensure that paragraphs are not split by
 empty lines

* lisp/ox-latex.el (org-latex-paragraph): If export creates single
paragraph contents with empty lines, remove the empty lines to ensure
that we retain a single paragraph.

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/tufdb6$11h2$1@ciao.gmane.io
---
 lisp/ox-latex.el | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index b84fe89db..f31d94da2 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2980,7 +2980,14 @@ (defun org-latex-paragraph (_paragraph contents _info)
   "Transcode a PARAGRAPH element from Org to LaTeX.
 CONTENTS is the contents of the paragraph, as a string.  INFO is
 the plist used as a communication channel."
-  contents)
+  ;; Ensure that we do not create multiple paragraphs, when a single
+  ;; paragraph is expected.
+  ;; Multiple newlines may appear in CONTENTS, for example, when
+  ;; certain objects are stripped from export, leaving single newlines
+  ;; before and after.
+  (replace-regexp-in-string
+   (rx (1+ (0+ space) "\n")) "\n"
+   contents))
 
 
 ;;;; Plain List
-- 
2.39.1


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
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>

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-11 10:38                               ` Ihor Radchenko
@ 2023-03-13 15:17                                 ` Max Nikulin
  2023-03-14 12:19                                   ` Ihor Radchenko
  2023-03-27 14:16                                 ` Ihor Radchenko
  1 sibling, 1 reply; 22+ messages in thread
From: Max Nikulin @ 2023-03-13 15:17 UTC (permalink / raw)
  To: emacs-orgmode

On 11/03/2023 17:38, Ihor Radchenko wrote:
> 
> Newlines are tricky. They may or may not be significant.
> For example, in CJK paragraphs, newlines are to be stripped.
> 
> I think that a reasonable thing to do could be not adding newlines if
> the previous object is a plain string ending with a newline.

It is in agreement with my expectation that the fix should not be 
LaTeX-specific. That is why I raised the issue in this thread.

> This is latex-specific.
> See the attached tentative fix.

> Reported-by: Max Nikulin <manikulin@gmail.com>
> Link: https://orgmode.org/list/tufdb6$11h2$1@ciao.gmane.io

and Max Nikulin to emacs-orgmode. Re: Comments break up a paragraph when 
writing one-setence-per-line. Sun, 3 Oct 2021 18:34:10 +0700. 
https://list.orgmode.org/sjc4fk$76r$1@ciao.gmane.io

> +  (replace-regexp-in-string
> +   (rx (1+ (0+ space) "\n")) "\n"
> +   contents))

What I do not like with this regexp is that it matches every newline 
character, not only blank lines:

(replace-regexp-in-string
  (rx (1+ (0+ space) "\n")) "[n]"
  "a   \nb")
"a[n]b"

If you still believe that a fix should be for LaTeX only then I would 
consider extra "\n": (rx "\n" (1+ (0+ space) "\n"))

I have realized that the following is a kind of pitfall in Org syntax:

#+macro: comment
Another
{{{comment(Paragraph separator! Do you expect it?)}}}
paragraph.



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-13 15:17                                 ` Max Nikulin
@ 2023-03-14 12:19                                   ` Ihor Radchenko
  0 siblings, 0 replies; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-14 12:19 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> On 11/03/2023 17:38, Ihor Radchenko wrote:
>> 
>> Newlines are tricky. They may or may not be significant.
>> For example, in CJK paragraphs, newlines are to be stripped.
>> 
>> I think that a reasonable thing to do could be not adding newlines if
>> the previous object is a plain string ending with a newline.
>
> It is in agreement with my expectation that the fix should not be 
> LaTeX-specific. That is why I raised the issue in this thread.

I still think that the issue with removing a lone object in a line is
LaTeX specific.

>> This is latex-specific.
>> See the attached tentative fix.
>
>> Reported-by: Max Nikulin <manikulin@gmail.com>
>> Link: https://orgmode.org/list/tufdb6$11h2$1@ciao.gmane.io
>
> and Max Nikulin to emacs-orgmode. Re: Comments break up a paragraph when 
> writing one-setence-per-line. Sun, 3 Oct 2021 18:34:10 +0700. 
> https://list.orgmode.org/sjc4fk$76r$1@ciao.gmane.io
>
> ....
> I have realized that the following is a kind of pitfall in Org syntax:
>
> #+macro: comment
> Another
> {{{comment(Paragraph separator! Do you expect it?)}}}
> paragraph.

I do not consider that a bug. Macros can insert anything, all the way to
headings - users who use the macros are expected to know what they are doing.

>> +  (replace-regexp-in-string
>> +   (rx (1+ (0+ space) "\n")) "\n"
>> +   contents))
>
> What I do not like with this regexp is that it matches every newline 
> character, not only blank lines:
>
> (replace-regexp-in-string
>   (rx (1+ (0+ space) "\n")) "[n]"
>   "a   \nb")
> "a[n]b"
>
> If you still believe that a fix should be for LaTeX only then I would 
> consider extra "\n": (rx "\n" (1+ (0+ space) "\n"))

Applied, onto main. With your amendment.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=3d04af382

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-11 10:38                               ` Ihor Radchenko
  2023-03-13 15:17                                 ` Max Nikulin
@ 2023-03-27 14:16                                 ` Ihor Radchenko
  2023-04-14 11:47                                   ` Ihor Radchenko
  1 sibling, 1 reply; 22+ messages in thread
From: Ihor Radchenko @ 2023-03-27 14:16 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 856 bytes --]

Ihor Radchenko <yantar92@posteo.net> writes:

> Max Nikulin <manikulin@gmail.com> writes:
>
>>>    [previous object <max(n1,n2) spaces>]
>>
>> Yes, you do.
>>
>> I expected some complications due to newline characters (not line break 
>> markup objects), but they are not included in :post-blank and 
>> represented as "\n" string objects.
>
> Newlines are tricky. They may or may not be significant.
> For example, in CJK paragraphs, newlines are to be stripped.
>
> I think that a reasonable thing to do could be not adding newlines if
> the previous object is a plain string ending with a newline.

I think that using max(n1,n2) is an overkill. There is no reason to
alter existing spaces before, if any.

I am attaching tentative patch that simply keeps spaces, but if and only
if the previous object does not end with whitespace (including newline).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-export-prune-tree-Ensure-spaces-when-removing-ob.patch --]
[-- Type: text/x-patch, Size: 3359 bytes --]

From 656c32d075d939aa69bc315bc91515930680377c Mon Sep 17 00:00:00 2001
Message-Id: <656c32d075d939aa69bc315bc91515930680377c.1679926405.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Mon, 27 Mar 2023 16:11:32 +0200
Subject: [PATCH] org-export--prune-tree: Ensure spaces when removing objects

* lisp/ox.el (org-export--prune-tree): If the removed object has
trailing spaces and previous object does not have, keep the trailing
spaces.
* etc/ORG-NEWS (Blank lines after removed objects are not retained
during export): Document the change.

Reported-by: Andrea Lazzarini <andrea.lazzarini1@gmail.com>
Link: https://orgmode.org/list/87o7p7z9k3.fsf@localhost
---
 etc/ORG-NEWS | 21 +++++++++++++++++++++
 lisp/ox.el   | 19 ++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index ac233a986..caf140279 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -145,6 +145,27 @@ execution completes.  The new ~:async~ header allows users to continue
 editing with Emacs while a ~:session~ block executes.
 
 ** Miscellaneous
+*** Blank lines after removed objects are not retained during export
+
+When certain objects in Org document are to be excluded from export,
+spaces after these objects were previously removed as well.
+
+For example, if ~org-export-with-footnotes~ is set to nil, the footnote in 
+
+: Pellentesque dapibus suscipit ligula.[fn:1]  Donec posuere augue in quam.
+
+would be removed, leading to the following exported ASCII document
+
+: Pellentesque dapibus suscipit ligula.Donec posuere augue in quam.
+
+This is because spaces after footnote (and other markup) are
+considered a part of the preceding AST object in Org.
+
+Now, unless there is a whitespace before an object to be removed,
+spaces are preserved during export:
+
+: Pellentesque dapibus suscipit ligula.  Donec posuere augue in quam.
+
 *** Remove undocumented ~:target~ header parameter in ~ob-clojure~
 
 The ~:target~ header was only used internally to distinguish
diff --git a/lisp/ox.el b/lisp/ox.el
index f9fc9a99b..206f0536d 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -2752,7 +2752,24 @@ (defun org-export--prune-tree (data info)
 		(let ((type (org-element-type data)))
 		  (if (org-export--skip-p data info selected excluded)
 		      (if (memq type '(table-cell table-row)) (push data ignore)
-			(org-element-extract-element data))
+			(let ((post-blank (org-element-property :post-blank data)))
+			  (if (or (not post-blank) (zerop post-blank)
+				  (eq 'element (org-element-class data)))
+			      (org-element-extract-element data)
+			    ;; Keep spaces in place of removed
+			    ;; element, if necessary.
+			    ;; Example: "Foo.[10%] Bar" would become
+			    ;; "Foo.Bar" if we do not keep spaces.
+			    (let ((previous (org-export-get-previous-element data info)))
+			      (if (or (not previous)
+				      (pcase (org-element-type previous)
+					(`plain-text
+					 (string-match-p
+					  (rx  whitespace eos) previous))
+					(_ (org-element-property :post-blank previous))))
+				  ;; Previous object ends with whitespace already.
+				  (org-element-extract-element data)
+				(org-element-set-element data (make-string post-blank ?\s)))))))
 		    (if (and (eq type 'headline)
 			     (eq (plist-get info :with-archived-trees)
 				 'headline)
-- 
2.39.1


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
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>

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)]
  2023-03-27 14:16                                 ` Ihor Radchenko
@ 2023-04-14 11:47                                   ` Ihor Radchenko
  0 siblings, 0 replies; 22+ messages in thread
From: Ihor Radchenko @ 2023-04-14 11:47 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> I am attaching tentative patch that simply keeps spaces, but if and only
> if the previous object does not end with whitespace (including newline).

Applied, onto main.
Fixed.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=960722661

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2023-04-14 11:52 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 10:07 [BUG] No space after footnote with org-export-with-footnotes set to nil [9.6.1 ( @ /Users/test/.emacs.d/elpa/28.0/develop/org-9.6.1/)] Andrea Lazzarini
2023-03-03 14:44 ` Max Nikulin
2023-03-03 15:47   ` Ihor Radchenko
2023-03-03 16:47     ` Max Nikulin
2023-03-04 15:43       ` Andrea Lazzarini
2023-03-05 12:06       ` Ihor Radchenko
2023-03-05 12:32         ` Andrea Lazzarini
2023-03-05 12:42           ` Ihor Radchenko
2023-03-05 12:54             ` Andrea Lazzarini
2023-03-05 13:01               ` Ihor Radchenko
2023-03-06 12:18                 ` Max Nikulin
2023-03-07 13:59                   ` Ihor Radchenko
2023-03-08 15:14                     ` Max Nikulin
2023-03-09 12:43                       ` Ihor Radchenko
2023-03-09 15:04                         ` Max Nikulin
2023-03-10 12:08                           ` Ihor Radchenko
2023-03-10 14:03                             ` Max Nikulin
2023-03-11 10:38                               ` Ihor Radchenko
2023-03-13 15:17                                 ` Max Nikulin
2023-03-14 12:19                                   ` Ihor Radchenko
2023-03-27 14:16                                 ` Ihor Radchenko
2023-04-14 11:47                                   ` Ihor Radchenko

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).