Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

special blocks end lists #8

Open
m3hgu5t4 opened this issue Feb 23, 2021 · 10 comments
Open

special blocks end lists #8

m3hgu5t4 opened this issue Feb 23, 2021 · 10 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@m3hgu5t4
Copy link

It seems that the blocks created by this package cause lists to stop when exporting, as well as generally leaving empty lines after the content in the exported file. Would it be possible to have the blocks remain inside the list?

An example:

1. builtin block
   #+begin_src latex
   \uline{does not end lists}
   #+end_src
2. org-special-blocks
   #+begin_proposition
   does not end lists
   #+end_proposition
3. org-special-block-extras builtin block
   #+begin_stutter 5
   this ends lists
   #+end_stutter
4. org-special-block-extras custom defblock
   #+begin_thm
   this ends lists
   #+end_thm

becomes

\begin{enumerate}
\item builtin block
\begin{verbatim}
   \uline{does not end lists}
\end{verbatim}
\item org-special-blocks
\begin{proposition}
does not end lists
\end{proposition}
\item org-special-block-extras builtin block
\end{enumerate}

this ends lists


this ends lists


this ends lists


this ends lists


this ends lists


\begin{enumerate}
\item org-special-block-extras custom defblock
\end{enumerate}
\begin{theorem}
this ends lists


\end{theorem}

and similarly in HTML.

@alhassy alhassy self-assigned this Feb 24, 2021
@alhassy
Copy link
Owner

alhassy commented Feb 24, 2021

This is a known issue ---I've been meaning to get to it for some time.

Maybe on the weekend I can get to it.


The problem seems to lie with org-special-block-extras--support-special-blocks-with-args, which does not save the indentation of a block when insert-ing the block's result.

@alhassy alhassy added bug Something isn't working help wanted Extra attention is needed labels Feb 24, 2021
@m3hgu5t4
Copy link
Author

Perhaps this could be solved by indenting the #+begin_export and #+end_export to match the line above/below?

@alhassy
Copy link
Owner

alhassy commented Feb 26, 2021

That was exactly the fix ;-)

Enjoy!

@alhassy alhassy closed this as completed Feb 26, 2021
@m3hgu5t4
Copy link
Author

Thanks for the update. This seems to fix the issue for blocks inside lists, but unfortunately not for blocks inside lists inside blocks. Would it be possible to instead indent the #+begin/end_export to the level of the #+begin/end_block tags before running the defblock'd function so that lists inside blocks aren't misaligned? Additonally, if you have time, I think de-indenting content before passing to the defblock'd function may make it easier to write a defblock that can be used inside lists.

@alhassy
Copy link
Owner

alhassy commented Feb 27, 2021

You're welcome =)

Hmmm, for blocks inside lists inside blocks I'm gonna need an example ;-)

In general, a block has complete control over its contents and it can decide what to do with inner blocks...

Maybe you want to use defblock not with contents (which does the exports) but instead with raw-contents?

@alhassy alhassy reopened this Feb 27, 2021
@m3hgu5t4
Copy link
Author

m3hgu5t4 commented Feb 27, 2021

For example,

#+begin_stutter 1
1. something\\
   this loses indent
2. something else
   #+begin_remark
   this loses indent
   #+end_remark
3. something else
#+end_stutter
1. something else
   #+begin_remark
   this keeps indent
   #+end_remark

where thm and prf are defblock'd. This becomes

#+begin_export latex 

#+end_export
1. something\\\\
this loses indent
2. something else
#+begin_export latex 
{\\color{black} \\fbox{\\bf [Editor Remark:} 
#+end_export
this loses indent

#+begin_export latex
\\fbox{\\bf ]}}
#+end_export
3. something else

#+begin_export latex

#+end_export
1. something else
   #+begin_export latex 
   {\\color{black} \\fbox{\\bf [Editor Remark:} 
   #+end_export
   this keeps indent

   #+begin_export latex
   \\fbox{\\bf ]}}
   #+end_export

after processing (this was taken from buffer-string at org-export-before-parsing-hook). The (indent-region blk-start (point) blk-column) forces all lines inside the block to have the same indent as the #+begin_block, which breaks lists as well as any other possible formatting requiring indentation. It might be better to instead only change the indent of the #+begin/end_export lines to match the level of the #+begin/end_block line before evaluating the defblock'd function, without affecting the content of the block at all.

@alhassy
Copy link
Owner

alhassy commented Feb 27, 2021

That's a good suggestion ---thank-you!
[ If you have edited the relevant code yourself, I'm happy to place it into the source ;-) ]

Would you please provide a more "realistic" use-case for this scenario; I haven't encountered it yet.

@m3hgu5t4
Copy link
Author

m3hgu5t4 commented Feb 27, 2021

I've been using this in my notes and this causes issues with things such as multiple-part theorems and lists of propositions containing proofs:

#+begin_props
- \(\Var(X) \geq 0\) and if \(\Var(X) = 0\), then \(\prob[X = {\expec{X}}] = 1\).
- If \(c \in \R\), then \(\Var(cX) = c^2 \Var(X)\).
- \(\Var(X) = \expec{X^2} - \expec{X}^2\)
  #+begin_prf :qed yes
  \begin{align*}
  \Var(X) &= \expec{(X - {\expec{X}})^2}\\
  &= \expec{X^2 - 2X\expec{X} + \expec{X}^2}\\
  &= \expec{X^2} - 2\expec{X}\times\expec{X} + \expec{X}^2\\
  &= \expec{X^2} - \expec{X}^2
  .\end{align*}
  #+end_prf
- \(\Var(X) = \min_{c\in\R}(\expec{(X-c)^2})\) and the minimum is achieved for \(c = \expec{X}\).
  #+begin_prf :qed yes
  Call \(f(c) = \expec{(X-c)^2} = \expec{X^2} - 2c\expec{X} + c^2\)
  
  Minimise \(f\) to get \(\min(f(c)) = f(\expec{X}) = \Var(X)\).
  #+end_prf
#+end_props

where props and prf just wrap the contents with \begin/\end{proposition/proof} in this case.

I don't think I'm familiar enough with both elisp and the structure of this package to be able to implement the change soon, but I think the change should be to remove the indent-region in 85e1ccd and to modify org-export and org-parse to have the #+begin/end_export copy the indent from the line after/before them.

Additionally it would make writing certain types of defblocks easier if, before sending contents, it counted the least indented line inside and deindented every line by that much, reindenting afterwards, so the defblock'd function sees the contents as though they weren't in a list, but this may be too complex or uncommon to reasonably implement.

@alhassy
Copy link
Owner

alhassy commented Feb 27, 2021

Thanks for the example =)

  • The prf + align combination is already built-into org-special-block-extras as calc ;-)

  • The most recent commit makes some progress, but does not yet fix the problem :'(

    I need to tinker with this a bit more, maybe your suggestion of modifying org-parse is the way to go.

  • Regarding the unindentation, do you mean something along the lines of this?

@m3hgu5t4
Copy link
Author

  • It seems as though the #+begin/end_export blocks around the content which are placed by org-export aren't being indented.
  • The unindentation I'm referring to is similar to that, but it seems like it may change relative indents if there's a line in the contents that's less indented than the first line, or otherwise cause issues if there are no indented lines. Ideally it would use the indent level of the least indented nonempty line, so it guarantees that line indents are preserved relative to each other.

alhassy added a commit that referenced this issue Aug 5, 2021
I've made some useful progress and have a solution.

Unfortunately, the solution infects other parts
of the system. The underlying cause is likely
around the use of ‘org-indent-region’, but there may
be more.

For now, I've left my explorations under the heading
“Issue ♯8”; which contains code that may eventually
migrate to the location where ‘defblock’ is implemented.

The system has gotten large and automated tests are
needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants