Browse Source

Allow empty strings in minted/listings latex options

* lisp/org-exp.el (org-export-format-source-code-or-example):
Allow empty string as second element in minted/listings options

Both

    (setq org-export-latex-minted-options
          '(("frame" "lines")
            ("fontsize" "\\scriptsize")
            ("linenos" "")))

and

    (setq org-export-latex-minted-options
          '(("frame" "lines")
            ("fontsize" "\\scriptsize")
            ("linenos")))

will result in latex like

\begin{minted}[frame=lines,fontsize=\scriptsize,linenos]{common-lisp}
Dan Davison 14 years ago
parent
commit
695b15da6d
1 changed files with 64 additions and 60 deletions
  1. 64 60
      lisp/org-exp.el

+ 64 - 60
lisp/org-exp.el

@@ -2428,66 +2428,70 @@ INDENT was the original indentation of the block."
 	       (org-add-props
 		   (cond
 		    ((and lang org-export-latex-listings)
-		     (let* ((lang-sym (intern lang))
-			    (minted-p (eq org-export-latex-listings 'minted))
-			    (listings-p (not minted-p))
-			    (backend-lang
-			     (or (cadr
-				  (assq
-				   lang-sym
-				   (cond
-				    (minted-p org-export-latex-minted-langs)
-				    (listings-p org-export-latex-listings-langs))))
-				 lang))
-			    (custom-environment
-			     (cadr
-			      (assq
-			       lang-sym
-			       org-export-latex-custom-lang-environments))))
-		       (concat
-			(when (and listings-p (not custom-environment))
-			  (format
-			   "\\lstset{%s}\n"
-			   (mapconcat
-			    (lambda (pair) (mapconcat #'identity pair "="))
-			    (append org-export-latex-listings-options
-				    `(("language" ,backend-lang))) ",")))
-			(when (and caption org-export-latex-listings-w-names)
-			  (format
-			   "\n%s $\\equiv$ \n"
-			   (replace-regexp-in-string "_" "\\\\_" caption)))
-			(cond
-			 (custom-environment
-			  (format "\\begin{%s}\n%s\\end{%s}\n"
-				  custom-environment rtn custom-environment))
-			 (listings-p
-			   (format "\\begin{%s}\n%s\\end{%s}\n"
-				   "lstlisting" rtn "lstlisting"))
-			 (minted-p
-			  (format
-			   "\\begin{minted}[%s]{%s}\n%s\\end{minted}\n"
-			   (mapconcat
-			    (lambda (pair) (mapconcat #'identity pair "="))
-			    org-export-latex-minted-options ",")
-			   backend-lang rtn))))))
-		    (t (concat (car org-export-latex-verbatim-wrap)
-			       rtn (cdr org-export-latex-verbatim-wrap))))
-		   '(org-protected t org-example t))
-	       "#+END_LaTeX\n"))
-	     ((eq backend 'ascii)
-	      ;; This is not HTML or LaTeX, so just make it an example.
-	      (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
-	      (concat caption "\n"
-		      "#+BEGIN_ASCII\n"
-		      (org-add-props
-			  (concat
-			   (mapconcat
-			    (lambda (l) (concat "  " l))
-			    (org-split-string rtn "\n")
-			    "\n")
-			   "\n")
-			  '(org-protected t org-example t))
-		      "#+END_ASCII\n"))))
+                     (flet ((make-option-string
+                             (pair)
+                             (concat (first pair)
+				     (if (> (length (second pair)) 0)
+					 (concat "=" (second pair))))))
+		       (let* ((lang-sym (intern lang))
+			      (minted-p (eq org-export-latex-listings 'minted))
+			      (listings-p (not minted-p))
+			      (backend-lang
+			       (or (cadr
+				    (assq
+				     lang-sym
+				     (cond
+				      (minted-p org-export-latex-minted-langs)
+				      (listings-p org-export-latex-listings-langs))))
+				   lang))
+			      (custom-environment
+			       (cadr
+				(assq
+				 lang-sym
+				 org-export-latex-custom-lang-environments))))
+			 (concat
+			  (when (and listings-p (not custom-environment))
+			    (format
+			     "\\lstset{%s}\n"
+			     (mapconcat
+			      #'make-option-string
+			      (append org-export-latex-listings-options
+				      `(("language" ,backend-lang))) ",")))
+			  (when (and caption org-export-latex-listings-w-names)
+			    (format
+			     "\n%s $\\equiv$ \n"
+			     (replace-regexp-in-string "_" "\\\\_" caption)))
+			  (cond
+			   (custom-environment
+			    (format "\\begin{%s}\n%s\\end{%s}\n"
+				    custom-environment rtn custom-environment))
+			   (listings-p
+			    (format "\\begin{%s}\n%s\\end{%s}\n"
+				    "lstlisting" rtn "lstlisting"))
+			   (minted-p
+			    (format
+			     "\\begin{minted}[%s]{%s}\n%s\\end{minted}\n"
+			     (mapconcat #'make-option-string
+					org-export-latex-minted-options ",")
+			     backend-lang rtn)))))))
+                    (t (concat (car org-export-latex-verbatim-wrap)
+                               rtn (cdr org-export-latex-verbatim-wrap))))
+                   '(org-protected t org-example t))
+               "#+END_LaTeX\n"))
+             ((eq backend 'ascii)
+              ;; This is not HTML or LaTeX, so just make it an example.
+              (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
+              (concat caption "\n"
+                      "#+BEGIN_ASCII\n"
+                      (org-add-props
+                          (concat
+                           (mapconcat
+                            (lambda (l) (concat "  " l))
+                            (org-split-string rtn "\n")
+                            "\n")
+                           "\n")
+                          '(org-protected t org-example t))
+                      "#+END_ASCII\n"))))
       (org-add-props rtn nil 'original-indentation indent))))
 
 (defun org-export-number-lines (text backend