dangom / org-thesis

Writing a Ph.D. thesis with Org Mode
498 stars 54 forks source link

How to deal with recursive includes? #10

Closed gpetrini closed 1 year ago

gpetrini commented 1 year ago

First of all, thank you a lot for this repo!

There is one thing that I cannot manage yet: how do you deal with relative paths?

For example, let's say that I have a folder thesis and a subfolder called research-chapter. In addition, I have a latex table (I cannot create it with org synthax) in ./thesis/research-chapter/tabs/table.tex. Inside ./research-chapter/manuscript.org I used

\input{./tabs/table.tex}

However, it is not detected by ./thesis/thesis.org (which has #+include:./research-chapter/manuscript.org). I tried to generate symbolic links, but this not seems to be a good solution. Do you recommend to use absolute paths instead?

If my pseudo-coded is not clear, I can provide the real file.

Thank you once more

dangom commented 1 year ago

Hi @gpetrini,

I've been meaning to clean up this repo for about 4 years but haven't come around to. The issues here (to my understanding) is that you are using latex syntax instead of org-mode syntax, which means that the latex is not parsed by org-mode during inclusion, and is copied as is. I would suggest mixing org-mode include and latex include, since that only increases complexity. Potential solutions:

Let me know how that goes.

Regards, Daniel

gpetrini commented 1 year ago

Hi @dangom, Thank you for your quick response. I tried to wrap my tables in export blocks as you suggested and it worked! However, I still cannot include figures in the thessis. This is unexpected because I am using the org-syntax in this case.

Here is the code:


#+caption: Expectational Vs. effective aggregate market-share (synthetic data)
#+attr_latex: :label ch_dotcom_fig_artificial_bubble :placement [htb]
[[file:./figs/Ch_DotCom_Stylized_Bubble.pdf]]```

Do you have any suggestions?
dangom commented 1 year ago

What's your Emacs/org-mode version?

gpetrini commented 1 year ago

It is exported as latex does not find the image path. In the research paper, it works, but not on the thesis.

Here is one example image

As a workaround, I am duplicating the figures in two folders, but this does not seems to be an org-modeish way of solving it.

dangom commented 1 year ago

No, the inclusion should work. There was an old bug with org-mode that would lead to this happening. I fixed it some 4,5 years ago, that's why I was wondering whether you weren't running an older org-mode version. So you are using the org-mode inclusion mechanism and your path is not being updated? Does this work if you use non-pdfs as figures? Does this work if you remove the attr_latex?

gpetrini commented 1 year ago

I am using org-mode version 9.6, so I think your fix is included. For including figure, I am using the link syntax as in your example and the path is not updated. I tried using png, using #+include syntax and remove attr_latex and got the same result :(

I guess that the problem is related to how org translate its own syntax to latex. The code that I sent to you earlier is the following in thesis.tex:

\begin{figure}[htb]
\centering
\includegraphics[width=.9\linewidth]{./figs/Ch_DotCom_Stylized_Bubble.png}
\caption{\label{ch_dotcom_fig_artificial_bubble}Expectational Vs. effective aggregate market-share (synthetic data)}
\end{figure}

I gues that the path is not being updated as you mentioned.

dangom commented 1 year ago

Can you get the thesis.org example to compile properly? Run C-c C-e l p on thesis.org? It works at my end and updates the path from the image at the research chapter. Both thesis and manuscript work.

Do you get the same issue there?

gpetrini commented 1 year ago

Yep, I get the same issue here.

Aparently, the path is not updated. Here is the error message:

Unable to read file "/home/gpetrini/Documents/org-thesis/thesis/manuscript.setup" [6 times]
org-babel-exp process elisp at position 5084...
Executing Elisp unknown (code)...
Code block evaluation complete.
Wrote /home/gpetrini/.emacs.d/.local/cache/undo-tree-hist/.d7a85b2b2517a4905bfe581b783bcffbea1411e0.~undo-tree~.zst
org-latex-headline: Wrong type argument: number-or-marker-p, nil

The first line suggest that it is looking for a file inside thesis, but it should be looked insed research-chapter.

I don't know if it helps, but I am using doom emacs.

dangom commented 1 year ago

I cannot reproduce. To debug this at your end I would call edebug-defun on org-export--prepare-file-contents, and then check what's going on by exporting the thesis to pdf and then stepping through the link conversion with edebug.

gpetrini commented 1 year ago

I tried what you mention and I have no clues. It seems that none of the paths are updated. For example, if a have a #+setupfile:manuscript.setup inside manuscript folder, it works fine for the research paper. However, the thesis.org file searches for a #+setupfile:manuscript.setup as it is, not updating the path.

gpetrini commented 1 year ago

Update: I was able to reproduce your pdf by just adapting the thesis.setup file. Thus, the problem is not related to org or emacs I guess. Possibly, I need to adjust the files at my end. Do you have any suggestion on how to debug it?

Thanks for your help.

gpetrini commented 1 year ago

I think I figured it out. My research-paper.org file also have #+includes. So, I think org prepares the relative links for the research-paper.org file and uses it as it is in the thesis.org. Do you know how to add more recursive links?

Fell free to close this issue.

dangom commented 1 year ago

Please open an issue with a simple example of the bug at the org mailing list, so devs can help. We'll keep this issue open until that gets fixed.

gpetrini commented 1 year ago

I came up with a simple workaround. Inside thesis.org I just replicated the contents (which have other includes) of research_paper.org and adjusted the path for each paper section. It is not ideial, but with that I do not need to create symbolic links.

dangom commented 1 year ago

I would just open an issue upstream; this seems like an easy fix. Here's where to submit: https://orgmode.org/worg/org-mailing-list.html

gpetrini commented 1 year ago

Ok, I've just sent it. I'll update this issue as soon as I get some answer.

gpetrini commented 1 year ago

FIX

dangom commented 1 year ago

Brilliant. Thanks for reporting and thanks for contributing to org-mode! Good luck with your thesis!