I'm writing my thesis in Org→Latex. As well as the individual chapter files, I keep track of the overall structure and progress in a separate file. One thing I look at and have to report on is the number of pages written versus the intended length.
I can use pdfinfo to get the number of physical pages in the individual chapters and get this into the outline with a code block. And I can generate a "columnview" table that automatically updates from the chapter info in the outline. I'd like to find out how I could put the two together.
Example
Hopefully this shows what I'm trying to do. In the real thing, there are obviously more like a dozen chapters.
#+TITLE: Thesis Outline
#+COLUMNS: %2ID %35ITEM %Target_Pages{+}
#+NAME: count-pdf-pages
#+BEGIN_SRC elisp :exports none :var pdf-file=""
(let
((pdf-file-info (shell-command-to-string (concat "pdfinfo " pdf-file))))
(string-match "Pages:[[:blank:]]+\\([0-9]+\\)" pdf-file-info)
(match-string 1 pdf-file-info)
)
#+END_SRC
* Chapter outlines
:PROPERTIES:
:ID: outlines
:END:
** 1. Introduction
:PROPERTIES:
:Target_Pages: 5
:END:
This is the introduction of the thesis. It currently has this many pages:
#+NAME: intro-page-count
#+CALL: count-pdf-pages("latex/intro-chapter.pdf")
* Page Allocation and Completion
#+BEGIN: columnview :hlines 1 :id outlines
| ID | ITEM | Target_Pages |
|----------+--------------------+--------------|
| outlines | * Chapter outlines | 5 |
| | ** 1. Introduction | 5 |
#+END
Question
What I would like to do is be able to use the return value of the CALL block for each chapter within the outline table at the end. However, having read through the relevant section of the manual a few times, I can't see whether it's possible to set a heading's property (say Written_Pages) to be the result of a code block.
Obviously, I'm also open to other org ways of approaching the problem of generating a table from the results of multiple code calls.
Org-mode properties can be set via elisp using org-set-properties. For example, (org-set-properties "Written_Pages" "5") (note that the property value must be a string. So just add an extra source block:
#+BEGIN_SRC elisp :export none :results none :var p=intro-page-count
(org-set-property "Written_Pages" p)
#+END_SRC
Related
I'm looking for a way to simplify the task of selecting from org-tree using hooking into the org-refile function.
It is known that through org-org refile it is possible to select certain subtrees and copy them under defined org-heading.
I don't need to copy all the content selected in the standard way from the subtree, but only take certain elements from the selected subtree such as:
todo-state from the parent heading. It ignores parent heading id/tags since it play as name of this group.
tags and id (from the properties) of each of the child headings. It is advisable to put it in a table.
Tags and todo are compiled into 1 column.
Take a look at this example. This is selection from large org-tree in the same file.
***** HEADER certain ways
****** some problem :Title:
:PROPERTIES:
:ID: 2022-06-07-09-24_some_problem
:END:
some content
***** SOLUTION where is solution living
****** read this topic :Topic:
:PROPERTIES:
:ID: 2022-04-23-topic
:END:
****** get the plan :One_way:
:PROPERTIES:
:CREATED: [2022-03-31 Thu 21:02]
:ID: 2022-06-06-15-12_get_the_plan
:END:
some content
the result will be not all selected subtrees but only their 'map' with IDs and tags which may be processed by requesting actual headings of large tree in the same file.
Result.
| Article part | ID |
-----------------------------------------------------------------
| Header Title | id:2022-06-07-09-24_some_problem |
| Solution Topic | id:2022-04-23-topic |
| Solution One_way | id:2022-06-06-15-12_get_the_plan |
For a while I've modified a snippet from this answer. But it requires additional step to copy all selected subtrees and then run this code under selection.
I'll be glad if it is possible to erase this step and compile such 'map' during org-refile process. Think it is possible through the org-refile hook.
In my case the sequence of headings/IDs one by one is important.
I'm making a little script using treesitter that will extract all code blocks inside an ORG file, but only if they're under an headline with a specific property (:TANGLE:).
I was able to make this query, which works, but only finds code blocks that are immediate children of the headline:
(section
(property_drawer
(property
name: (expr) #prop_name (#eq? #prop_name "TANGLE")
value: (value) #file
)
)
(body
(block
contents: (contents) #code
)
)
)
It works with this org file:
* Headline
:PROPERTIES:
:TANGLE: file.lua
:END:
#+begin_src lua
print("test")
#+end_src
But not with this one, because the code block is not directly inside "Headline 1":
* Headline 1
:PROPERTIES:
:TANGLE: file.lua
:END:
** Headline 2
#+begin_src lua
print("test")
#+end_src
Is there a way using treesitter queries to get nodes nested at any depth inside the headline?
I couldn't find any way to do that, so in the end, I decided to do a deep search recursively.
This was a script for neovim, so I used these functions:
tsnode:iter_children() -- used in a for loop
tsnode:type() -- Check the node type
ts_utils.get_node_text() -- To get the text content of a node
I hope this could be helpful for others too.
How do I define the space allocated to the footnotes in an Org file that is intended to be exported as a Beamer presentation? The problematic result is shown below:
The relevant bit of Org file looks like this:
#+STARTUP: beamer
#+LaTeX_CLASS: beamer
#+LaTeX_CLASS_OPTIONS: [bigger]
#+BEAMER_FRAME_LEVEL: 2
#+COLUMNS: %40ITEM %10BEAMER_env(Env) %9BEAMER_envargs(Env Args) %4BEAMER_col(Col) %10BEAMER_extra(Extra)
* Role of Org-Babel
** Overview :B_verse:
:PROPERTIES:
:BEAMER_env: verse
:END:
=org-babel= is a facility that provides inline code evaluation,
highlighting and tangling[fn:1: Tangling and untangling is the
process employed in literate programming for hiding and displaying
code blocks.].
PS. Of course literate programming.
Add the following option in your header:
#+LaTeX_HEADER:\addtobeamertemplate{footnote}{}{\vspace{2ex}}
So, I use org-mode extensively for my daily TODO requirements. I am wondering if I can also use it effectively for note keeping. What I basically want is to store notes with tags, and then want to search these notes by the tags. E.g. If I have something like this
* Heading 1
** Note 1 :tag1:tag2:
Note 1 details
** Note 2 :tag3:
Note 2 details
* Heading 2
** Note 3
** Note 4 :tag1:
Note 4 details
and then I search for tag1, I should have something like-
* Heading 1
** Note 1 :tag1:tag2:
Note 1 details
* Heading 2
** Note 4 :tag1:
Note 4 details
I would prefer being able to do this without adding the files to my agenda. (I may have several of these notes, and I would only want to search the current file at a time.)
Is there an easy (or not so easy) way to accomplish this org-mode?
The following function should provide the result you want.
(defun zin/org-tag-match-context (&optional todo-only match)
"Identical search to `org-match-sparse-tree', but shows the content of the matches."
(interactive "P")
(org-prepare-agenda-buffers (list (current-buffer)))
(org-overview)
(org-remove-occur-highlights)
(org-scan-tags '(progn (org-show-entry)
(org-show-context))
(cdr (org-make-tags-matcher match)) todo-only))
You can use a tag search (C-c / m tag1 <ret>). Documentation here:
http://orgmode.org/manual/Tag-searches.html
This will create a sparse tree showing only the headings containing :tag1:, but it will not automatically reveal the contents of that heading as in your example.
In standard Latex, one can use something like...
\section[short head]{A longer and more meaningful heading version for the section}
...that gives both a long and short version of a section (or other sectioning command) Thus, allowing for both meaningful sectioning 'titles' and, also, reasonable-looking running heads, TOCs, beamer navigation, etc..
Is there any way to easily achieve this in org mode? (That is without hard coding the sectioning commands in LATEX snippets and, thus, defeating most of the flexibility of changing sectioning levels and repurposing content for beamer, book, and article classes that is my reason for wanting to try orgmode, in first place?)
I tried a "workaround" that did not work. I tried editing the possible latex export classes by adding another class to org-export-latex-classes. This new class changes sectioning commands from \section{%s} to \section%s(EDIT-Fixed typo in slashes). Then I tested using [short]{longer version} in orgmode sections of the file. It worked, except it acted as if the longer version section heading was just "{" and "longer version" was body text! What is up with that?
Since version 8.0 the "org-export-latex-classes" strategy won't work anymore.
Instead, and dare I say much more elegantly, you can set the ALT_TITLE property for the heading.
See http://orgmode.org/manual/Table-of-contents.html.
The following org code:
* The Long Title of Section 1
:PROPERTIES:
:ALT_TITLE: Section 1
:END:
Lorem ipsum.
** The Long Title of Subsection 1-1
:PROPERTIES:
:ALT_TITLE: Subsection 1-1
:END:
Dolor sit amet.
will export to LaTeX as:
[...]
\section[Section 1]{The Long Title of Section 1}
\label{sec-1}
Lorem ipsum.
\subsection[Subsection 1-1]{The Long Title of Subsection 1-1}
\label{sec-1-1}
Dolor sit amet.
You had the right idea with creating your own LaTeX class. The problem lies with the way the templates are filled by the default org-fill-template function. I'm not so great with Lisp, but this this hack will do the trick. Add the following to your .emacs file:
(defun my-section (level text)
(let* ((in "") (out "")
(short-title (if (string-match "\\[.*\\]" text)
(substring text (match-beginning 0)
(match-end 0))
nil)))
(if short-title (setq text (substring text (match-end 0) -1)))
(setq in (org-fill-template
"\\section%S{%s}"
(list (cons "S" (or short-title ""))
(cons "s" (or text ""))))
out (copy-sequence "\\end{section}"))
(cons text (list in out in out))))
(add-to-list 'org-export-latex-classes
'("test"
"\\documentclass{article}"
my-section))
This declares a new latex class by adding a "test" class to the org-export-latex-classes. Here we declare, instead of the normal \\section{%s} stuff a function that takes two parameters --- the current level and the headline text --- and returns a modified cons cell. Some details of this information can be found in org-latex-export.el.
Above the adding to the list is where we actually define the function. This is honestly a hacky version, and I pulled a lot from the org-beamer-sectioning function in org-beamer.el file. This function basically searches the headline for anything that is like a LaTeX short label (i.e. [....]) removes it from the headline and sticks it before the actual section label. Right now this hack will only generate \section statements, no matter how deep the level - if you want something more intelligent like \chapter or \subsection or even unnumbered items, you'll need to do some more Lisping; again, see org-beamer.el for some help.
This bit of org-mode code
#+latex_class: test
* [short 1] this is 1 star
test
** this is a 2 star
test
*** [short 3] this is a 3 star
test
**** what happens
exports to LaTeX as (only relevant sections shown here):
\section[short 1]{ this is 1 star}
\label{sec-1}
test
\section{ this is a 2 star }
\label{sec-1-1}
test
\section[short 3]{ this is a 3 star}
\label{sec-1-1-1}
test
\section{ what happens }
\label{sec-1-1-1-1}
\end{section}
\end{section}
\end{section}
\end{section}
Although it's not a straight org-mode solution, it seems to work and can be a starting point for you. One of these days I might try to write it up properly and get it folded into the org-mode distribution.
It is possible to use the following commands in latex to define the text that should appear in the header to replace section names. But the TOC will still contain the original names.
\chaptermarks
\sectionmarks
\subsectionmarks
...
So, in org-mode you can write
* Long section title
#+LaTeX: \sectionmark{Short title}
edit: it actually doesn't work on the very page where the section name appears. On this one only, the full name is still put in the header.