0

Is there a way to set the UNNUMBERED property only to the current heading but not to the children headings?

My desired headings are:

1 Part one
  1.1 Chapter one
Appendixes               (unnumbered)
  A Appendix one         (numbered)
  B Appendix two         (numbered)

leaving apart the letters for Appendixes (see "EXTRA" below), I can get this result with:

* Part one
** Chapter one
* Appendixes
:PROPERTIES:
:UNNUMBERED: t
:END:
** Appendix one
:PROPERTIES:
:UNNUMBERED: nil
:END:
** Appendix two
:PROPERTIES:
:UNNUMBERED: nil
:END:

but repeating the UNNUMBERED: nil for each appendix is boring and not so good for future changes, so I tried to group appendix in a phantom header (with (ox-extras-activate '(ignore-headlines))):

* Part one
** Chapter one
* Appendixes
:PROPERTIES:
:UNNUMBERED: t
:END:
** core :ignore:
:PROPERTIES:
:UNNUMBERED: nil
:END:
*** Appendix one
*** Appendix two

but with this I get:

1 Part one
  1.1 Chapter one
Appendixes
  Appendix one
  Appendix two

so it does not ignore the heading only, but also its properties.

I am exporting both to LaTeX and HTML/ePub, so a solution involving LaTeX custom export is not possible.

UPDATE
As suggested by @NickD I checkd the variable org-use-property-inheritance was set to nil. It was, so maybe the UNNUMBERED property has forced inheritance like other properties.

* Part one
Lorem Ipsum
** Chapter one
Dolor sit amet
* Appendixes
:PROPERTIES:
:UNNUMBERED: t
:END:
Lorem Ipsum
** Appendix one
Dolor sit amet
** Appendix two
Lorem Ipsum

with org-use-property-inheritance equal to nil generates

% Created 2021-08-23 lun 09:46
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\usepackage{tikz}
\usepackage{bookmark}
\author{Davide Peressoni}
\date{\today}
\title{}
\hypersetup{
 pdfauthor={Davide Peressoni},
 pdftitle={},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 27.2 (Org mode 9.5)}, 
 pdflang={English}}
\begin{document}

\tableofcontents

\section{Part one}
\label{sec:orgd36625b}
Lorem Ipsum
\subsection{Chapter one}
\label{sec:orgc5dae8d}
Dolor sit amet
\section*{Appendixes}
\label{sec:orgf878691}
Lorem Ipsum
\subsection*{Appendix one}
\label{sec:org0d45b16}
Dolor sit amet
\subsection*{Appendix two}
\label{sec:org848be4e}
Lorem Ipsum
\end{document}

EXTRA
If someone is interested I'm using this function to achieve the same numbering of LaTeX in HTML (parts in roman, chapters continuous among parts and appendix chapters in alpha):

(defun org-export-get-headline-number (headline info)
    "Return numbered HEADLINE numbering as a list of numbers.
INFO is a plist holding contextual information."
    (and (org-export-numbered-headline-p headline info)
         (let* (
                (nums (cdr (assq headline (plist-get info :headline-numbering))))
                (root-heading (let ((parent headline)(temp)) (while (and (setq temp (org-element-property :parent parent)) (eq 'headline (org-element-type temp))) (setq parent temp)) parent))
                (appendix (member "appendix" (org-element-property :tags root-heading))))
           (if (eq 1 (length nums))
               ;; if it's a part get roman numbers
               (list (nth (car nums) '("Z" "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX" "X")))
             (let ((nums (cdr nums))) ; remove part number
               (cons (if appendix
                         ;; appendix chapters in alpha
                         (byte-to-string (- (+ ?A (car nums)) 1))
                       (+ (car nums) ; sum chapters of previous parts
                          (-count 'identity
                           (org-element-map (org-element-property :parent root-heading) 'headline
                             (lambda (el)
                               (and
                                (eq 2 (org-element-property :level el))
                                (< (org-element-property :begin el) (org-element-property :begin root-heading))))))))
                     (cdr nums))
               )))))
  (defun number-to-string (number)
    (format "%s" number))
  )
6
  • 1
    What is the value of org-use-property-inheritance in the buffer? If t, do you need it to be so? If not, set it to nil.
    – NickD
    Aug 20, 2021 at 16:32
  • I didn't know of this variable. Printing with (eval (if org-use-property-inheritance "t" "nil")) inside an org-macro returns that it is set to nil. I tried also to reset it to nil with this code, but, obviously, nothing changed: ``` #+BEGIN_SRC elisp :exports results :results none :eval export (setq org-use-property-inheritance nil) #+END_SRC ```
    – DPD-
    Aug 21, 2021 at 8:03
  • 1
    You can use C-h v org-use-property-inheritance (or whatever other variable you want to see the value of) in the buffer of interest: that will give you the buffer-local value of the variable much more easily. If it is not set, then inheritance should not be active for properties, so you should not have to set the property in each individual appendix (at least that's the theory - practice may be different :-) )
    – NickD
    Aug 21, 2021 at 13:30
  • 1
    I think you are right: the description in the manual says "Set ‘UNNUMBERED’ property to non-‘nil’ to disable numbering of heading and subheadings entirely" (emphasis added). More's the pity...
    – NickD
    Aug 23, 2021 at 13:28
  • 1
    Exactily: seeing the code of org-export-numbered-headline-p I found it uses (org-export-get-node-property :UNNUMBERED headline t) and the last t tells to force using inheritance. So a "solution" could be to override this function.
    – DPD-
    Aug 23, 2021 at 18:50

1 Answer 1

1

Following the suggestions of @NickD I figured out this hack to break the inheritance of UNNUMBERED property:

;; Break inheritance of UNNUMBERED
(defun org-export-numbered-headline-p (headline info)
  "Return a non-nil value if HEADLINE element should be numbered.
INFO is a plist used as a communication channel."
  (unless (org-not-nil (org-export-get-node-property :UNNUMBERED headline  ))
                                                      ; removing `t` here ↑
                                                      ; removes inheritance
    (let ((sec-num (plist-get info :section-numbers))
      (level (org-export-get-relative-level headline info)))
      (if (wholenump sec-num) (<= level sec-num) sec-num))))

With that the chapters in appendix are numbered continuing from previous part, to avoid this I changed the function to assign headlines numbering in this way (also including roman for parts and letters for appendix):

;; Numbering
  (defun org-export-get-headline-number (headline info)
    "Return numbered HEADLINE numbering as a list of numbers.
INFO is a plist holding contextual information."
    (and (org-export-numbered-headline-p headline info)
         (let* (
                (nums (cdr (assq headline (plist-get info :headline-numbering))))
                (root-heading (let ((parent headline)(temp)) (while (and (setq temp (org-element-property :parent parent)) (eq 'headline (org-element-type temp))) (setq parent temp)) parent))
                (appendix (member "appendix" (org-element-property :tags root-heading))))
           (if (eq 1 (length nums))
               ;; if it's a part get roman numbers
               (list (nth (car nums) '("Z" "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX" "X")))
             (let ((nums (cdr nums))) ; remove part number
               (cons (if appendix
                         ;; appendix chapters in alpha
                         (byte-to-string
                          (-
                           (+ ?A (car nums))
                           (nth 1 (cdr (assq
                                      (org-element-map root-heading 'headline (lambda (el) (when (org-export-numbered-headline-p el info) el)) nil t)
                                      (plist-get info :headline-numbering)))) ; number of first appendix
                        ))
                       (+ (car nums) ; sum chapters of previous parts
                          (-count 'identity
                           (org-element-map (org-element-property :parent root-heading) 'headline
                             (lambda (el)
                               (and
                                (eq 2 (org-element-property :level el))
                                (< (org-element-property :begin el) (org-element-property :begin root-heading))))))))
                     (cdr nums))
               )))))
  (defun number-to-string (number)
    (format "%s" number))
  )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.