Bladeren bron

Implement limited headine numbering for e-latex and e-ascii back-ends

* contrib/lisp/org-export.el (org-export-with-section-numbers): Modify
  doc-string to document the changes.
* EXPERIMENTAL/org-e-ascii.el (org-e-ascii--build-title): Implement
  limited headline numbering.
* EXPERIMENTAL/org-e-latex.el (org-e-latex-template): Implement
  limited headline numbering.
Nicolas Goaziou 13 jaren geleden
bovenliggende
commit
d9970d1bd9
3 gewijzigde bestanden met toevoegingen van 33 en 19 verwijderingen
  1. 16 9
      EXPERIMENTAL/org-e-ascii.el
  2. 14 10
      EXPERIMENTAL/org-e-latex.el
  3. 3 0
      contrib/lisp/org-export.el

+ 16 - 9
EXPERIMENTAL/org-e-ascii.el

@@ -563,13 +563,20 @@ specifications.
 if optional argument NOTAGS is nil, no tags will be added to the
 title."
   (let* ((headlinep (eq (car element) 'headline))
-	 ;; Numbering is specific to headlines.
-	 (numbers (and headlinep (plist-get info :section-numbers)
-		       (concat
-			(mapconcat
-			 #'number-to-string
-			 (org-export-get-headline-number element info) ".")
-			" ")))
+	 (numbers
+	  ;; Numbering is specific to headlines.
+	  (and headlinep
+	       ;; Section numbering must be active, and headline's
+	       ;; level should be above specified limit, if any.
+	       (let ((sec-num (plist-get info :section-numbers)))
+		 (if (not (wholenump sec-num)) sec-num
+		   (<= (org-export-get-relative-level headline info) sec-num)))
+	       ;; All tests passed: build numbering string.
+	       (concat
+		(mapconcat
+		 #'number-to-string
+		 (org-export-get-headline-number element info) ".")
+		" ")))
 	 (text (org-export-secondary-string
 		(org-element-get-property :title element) 'e-ascii info))
 	 (todo
@@ -593,8 +600,8 @@ title."
 	(format " %%%ds"
 		(max (- text-width  (1+ (length first-part))) (length tags)))
 	tags))
-     ;; Maybe underline text, if ELEMENT type is `headline' and
-     ;; a underline character has been defined.
+     ;; Maybe underline text, if ELEMENT type is `headline' and an
+     ;; underline character has been defined.
      (when (and underline headlinep)
        (let ((under-char
 	      (nth (1- (org-export-get-relative-level element info))

+ 14 - 10
EXPERIMENTAL/org-e-latex.el

@@ -803,7 +803,11 @@ holding export options."
 	    (plist-get info :latex-header-extra))))))
      ;; 3. Define alert if not yet defined.
      "\\providecommand{\\alert}[1]{\\textbf{#1}}\n"
-     ;; 4. Author.
+     ;; 4. Possibly limit depth for headline numbering.
+     (let ((sec-num (plist-get info :section-numbers)))
+       (when (integerp sec-num)
+	 (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
+     ;; 5. Author.
      (let ((author (and (plist-get info :with-author)
 			(let ((auth (plist-get info :author)))
 			  (and auth (org-export-secondary-string
@@ -815,12 +819,12 @@ holding export options."
 	      (format "\\author{%s\\thanks{%s}}\n" author email))
 	     (author (format "\\author{%s}\n" author))
 	     (t "\\author{}\n")))
-     ;; 5. Date.
+     ;; 6. Date.
      (let ((date (plist-get info :date)))
        (and date (format "\\date{%s}\n" date)))
-     ;; 6. Title
+     ;; 7. Title
      (format "\\title{%s}\n" title)
-     ;; 7. Hyperref options.
+     ;; 8. Hyperref options.
      (format "\\hypersetup{\n  pdfkeywords={%s},\n  pdfsubject={%s},\n  pdfcreator={%s}}\n"
 	     (or (plist-get info :keywords) "")
 	     (or (plist-get info :description) "")
@@ -829,9 +833,9 @@ holding export options."
 		((not creator-info) "")
 		((eq creator-info 'comment) "")
 		(t (plist-get info :creator)))))
-     ;; 7. Document start.
+     ;; 9. Document start.
      "\\begin{document}\n\n"
-     ;; 8. Title command.
+     ;; 10. Title command.
      (org-element-normalize-string
       (cond ((string= "" title) nil)
 	    ((not (stringp org-e-latex-title-command)) nil)
@@ -839,22 +843,22 @@ holding export options."
 			   org-e-latex-title-command)
 	     (format org-e-latex-title-command title))
 	    (t org-e-latex-title-command)))
-     ;; 9. Table of contents.
+     ;; 11. Table of contents.
      (let ((depth (plist-get info :with-toc)))
        (when depth
 	 (concat (when (wholenump depth)
 		   (format "\\setcounter{tocdepth}{%d}\n" depth))
 		 "\\tableofcontents\n\\vspace*{1cm}\n\n")))
-     ;; 10. Document's body.
+     ;; 12. Document's body.
      contents
-     ;; 11. Creator.
+     ;; 13. Creator.
      (let ((creator-info (plist-get info :with-creator)))
        (cond
 	((not creator-info))
 	((eq creator-info 'comment)
 	 (format "%% %s\n" (plist-get info :creator)))
 	(t (concat (plist-get info :creator) "\n"))))
-     ;; 12. Document end.
+     ;; 14. Document end.
      "\\end{document}")))
 
 

+ 3 - 0
contrib/lisp/org-export.el

@@ -394,6 +394,9 @@ When nil, remove priority cookies for export."
 (defcustom org-export-with-section-numbers t
   "Non-nil means add section numbers to headlines when exporting.
 
+When set to an integer n, numbering will only happen for
+headlines whose relative level is higher or equal to n.
+
 This option can also be set with the #+OPTIONS line,
 e.g. \"num:t\"."
   :group 'org-export-general