+ (message "Exposing entire buffer...")
+ (allout-flag-region (point-min) (point-max) ?\n)
+ (message "Exposing entire buffer... Done."))
+;;;_ > allout-hide-bodies ()
+(defun allout-hide-bodies ()
+ "Hide all of buffer except headings."
+ (interactive)
+ (allout-hide-region-body (point-min) (point-max)))
+;;;_ > allout-hide-region-body (start end)
+(defun allout-hide-region-body (start end)
+ "Hide all body lines in the region, but not headings."
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (goto-char (point-min))
+ (while (not (eobp))
+ (allout-flag-region (point)
+ (progn (allout-pre-next-preface) (point)) ?\r)
+ (if (not (eobp))
+ (forward-char
+ (if (looking-at "[\n\r][\n\r]")
+ 2 1)))))))
+
+;;;_ > allout-expose-topic (spec)
+(defun allout-expose-topic (spec)
+ "Apply exposure specs to successive outline topic items.
+
+Use the more convenient frontend, `allout-new-exposure', if you don't
+need evaluation of the arguments, or even better, the `allout-layout'
+variable-keyed mode-activation/auto-exposure feature of allout outline
+mode. See the respective documentation strings for more details.
+
+Cursor is left at start position.
+
+SPEC is either a number or a list.
+
+Successive specs on a list are applied to successive sibling topics.
+
+A simple spec \(either a number, one of a few symbols, or the null
+list) dictates the exposure for the corresponding topic.
+
+Non-null lists recursively designate exposure specs for respective
+subtopics of the current topic.
+
+The `:' repeat spec is used to specify exposure for any number of
+successive siblings, up to the trailing ones for which there are
+explicit specs following the `:'.
+
+Simple (numeric and null-list) specs are interpreted as follows:
+
+ Numbers indicate the relative depth to open the corresponding topic.
+ - negative numbers force the topic to be closed before opening to the
+ absolute value of the number, so all siblings are open only to
+ that level.
+ - positive numbers open to the relative depth indicated by the
+ number, but do not force already opened subtopics to be closed.
+ - 0 means to close topic - hide all offspring.
+ : - `repeat'
+ apply prior element to all siblings at current level, *up to*
+ those siblings that would be covered by specs following the `:'
+ on the list. Ie, apply to all topics at level but the last
+ ones. \(Only first of multiple colons at same level is
+ respected - subsequent ones are discarded.)
+ * - completely opens the topic, including bodies.
+ + - shows all the sub headers, but not the bodies
+ - - exposes the body of the corresponding topic.
+
+Examples:
+\(allout-expose-topic '(-1 : 0))
+ Close this and all following topics at current level, exposing
+ only their immediate children, but close down the last topic
+ at this current level completely.
+\(allout-expose-topic '(-1 () : 1 0))
+ Close current topic so only the immediate subtopics are shown;
+ show the children in the second to last topic, and completely
+ close the last one.
+\(allout-expose-topic '(-2 : -1 *))
+ Expose children and grandchildren of all topics at current
+ level except the last two; expose children of the second to
+ last and completely open the last one."
+
+ (interactive "xExposure spec: ")
+ (if (not (listp spec))
+ nil
+ (let ((depth (allout-depth))
+ (max-pos 0)
+ prev-elem curr-elem
+ stay done
+ snug-back
+ )
+ (while spec
+ (setq prev-elem curr-elem
+ curr-elem (car spec)
+ spec (cdr spec))
+ (cond ; Do current element:
+ ((null curr-elem) nil)
+ ((symbolp curr-elem)
+ (cond ((eq curr-elem '*) (allout-show-current-subtree)
+ (if (> allout-recent-end-of-subtree max-pos)
+ (setq max-pos allout-recent-end-of-subtree)))
+ ((eq curr-elem '+) (allout-show-current-branches)
+ (if (> allout-recent-end-of-subtree max-pos)
+ (setq max-pos allout-recent-end-of-subtree)))
+ ((eq curr-elem '-) (allout-show-current-entry))
+ ((eq curr-elem ':)
+ (setq stay t)
+ ;; Expand the `repeat' spec to an explicit version,
+ ;; w.r.t. remaining siblings:
+ (let ((residue ; = # of sibs not covered by remaining spec
+ ;; Dang - could be nice to make use of the chart, sigh:
+ (- (length (allout-chart-siblings))
+ (length spec))))
+ (if (< 0 residue)
+ ;; Some residue - cover it with prev-elem:
+ (setq spec (append (make-list residue prev-elem)
+ spec)))))))
+ ((numberp curr-elem)
+ (if (and (>= 0 curr-elem) (allout-visible-p))
+ (save-excursion (allout-hide-current-subtree t)
+ (if (> 0 curr-elem)
+ nil
+ (if (> allout-recent-end-of-subtree max-pos)
+ (setq max-pos
+ allout-recent-end-of-subtree)))))
+ (if (> (abs curr-elem) 0)
+ (progn (allout-show-children (abs curr-elem))
+ (if (> allout-recent-end-of-subtree max-pos)
+ (setq max-pos allout-recent-end-of-subtree)))))
+ ((listp curr-elem)
+ (if (allout-descend-to-depth (1+ depth))
+ (let ((got (allout-expose-topic curr-elem)))
+ (if (and got (> got max-pos)) (setq max-pos got))))))
+ (cond (stay (setq stay nil))
+ ((listp (car spec)) nil)
+ ((> max-pos (point))
+ ;; Capitalize on max-pos state to get us nearer next sibling:
+ (progn (goto-char (min (point-max) max-pos))
+ (allout-next-heading)))
+ ((allout-next-sibling depth))))
+ max-pos)))
+;;;_ > allout-old-expose-topic (spec &rest followers)
+(defun allout-old-expose-topic (spec &rest followers)
+
+ "Deprecated. Use `allout-expose-topic' \(with different schema
+format) instead.
+
+Dictate wholesale exposure scheme for current topic, according to SPEC.
+
+SPEC is either a number or a list. Optional successive args
+dictate exposure for subsequent siblings of current topic.
+
+A simple spec (either a number, a special symbol, or the null list)
+dictates the overall exposure for a topic. Non null lists are
+composite specs whose first element dictates the overall exposure for
+a topic, with the subsequent elements in the list interpreted as specs
+that dictate the exposure for the successive offspring of the topic.
+
+Simple (numeric and null-list) specs are interpreted as follows:
+
+ - Numbers indicate the relative depth to open the corresponding topic:
+ - negative numbers force the topic to be close before opening to the
+ absolute value of the number.
+ - positive numbers just open to the relative depth indicated by the number.
+ - 0 just closes
+ - `*' completely opens the topic, including bodies.
+ - `+' shows all the sub headers, but not the bodies
+ - `-' exposes the body and immediate offspring of the corresponding topic.
+
+If the spec is a list, the first element must be a number, which
+dictates the exposure depth of the topic as a whole. Subsequent
+elements of the list are nested SPECs, dictating the specific exposure
+for the corresponding offspring of the topic.
+
+Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
+
+ (interactive "xExposure spec: ")
+ (let ((depth (allout-current-depth))
+ done
+ max-pos)
+ (cond ((null spec) nil)
+ ((symbolp spec)
+ (if (eq spec '*) (allout-show-current-subtree))
+ (if (eq spec '+) (allout-show-current-branches))
+ (if (eq spec '-) (allout-show-current-entry)))
+ ((numberp spec)
+ (if (>= 0 spec)
+ (save-excursion (allout-hide-current-subtree t)
+ (end-of-line)
+ (if (or (not max-pos)
+ (> (point) max-pos))
+ (setq max-pos (point)))
+ (if (> 0 spec)
+ (setq spec (* -1 spec)))))
+ (if (> spec 0)
+ (allout-show-children spec)))
+ ((listp spec)
+ ;(let ((got (allout-old-expose-topic (car spec))))
+ ; (if (and got (or (not max-pos) (> got max-pos)))
+ ; (setq max-pos got)))
+ (let ((new-depth (+ (allout-current-depth) 1))
+ got)
+ (setq max-pos (allout-old-expose-topic (car spec)))
+ (setq spec (cdr spec))
+ (if (and spec
+ (allout-descend-to-depth new-depth)
+ (not (allout-hidden-p)))
+ (progn (setq got (apply 'allout-old-expose-topic spec))
+ (if (and got (or (not max-pos) (> got max-pos)))
+ (setq max-pos got)))))))
+ (while (and followers
+ (progn (if (and max-pos (< (point) max-pos))
+ (progn (goto-char max-pos)
+ (setq max-pos nil)))
+ (end-of-line)
+ (allout-next-sibling depth)))
+ (allout-old-expose-topic (car followers))
+ (setq followers (cdr followers)))
+ max-pos))
+;;;_ > allout-new-exposure '()
+(defmacro allout-new-exposure (&rest spec)
+ "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
+Some arguments that would need to be quoted in `allout-expose-topic'
+need not be quoted in `allout-new-exposure'.
+
+Cursor is left at start position.
+
+Use this instead of obsolete `allout-exposure'.
+
+Examples:
+\(allout-new-exposure (-1 () () () 1) 0)
+ Close current topic at current level so only the immediate
+ subtopics are shown, except also show the children of the
+ third subtopic; and close the next topic at the current level.
+\(allout-new-exposure : -1 0)
+ Close all topics at current level to expose only their
+ immediate children, except for the last topic at the current
+ level, in which even its immediate children are hidden.
+\(allout-new-exposure -2 : -1 *)
+ Expose children and grandchildren of first topic at current
+ level, and expose children of subsequent topics at current
+ level *except* for the last, which should be opened completely."
+ (list 'save-excursion
+ '(if (not (or (allout-goto-prefix)
+ (allout-next-heading)))
+ (error "allout-new-exposure: Can't find any outline topics"))
+ (list 'allout-expose-topic (list 'quote spec))))
+
+;;;_ #7 Systematic outline presentation - copying, printing, flattening
+
+;;;_ - Mapping and processing of topics
+;;;_ ( See also Subtree Charting, in Navigation code.)
+;;;_ > allout-stringify-flat-index (flat-index)
+(defun allout-stringify-flat-index (flat-index &optional context)
+ "Convert list representing section/subsection/... to document string.
+
+Optional arg CONTEXT indicates interior levels to include."
+ (let ((delim ".")
+ result
+ numstr
+ (context-depth (or (and context 2) 1)))
+ ;; Take care of the explicit context:
+ (while (> context-depth 0)
+ (setq numstr (int-to-string (car flat-index))
+ flat-index (cdr flat-index)
+ result (if flat-index
+ (cons delim (cons numstr result))
+ (cons numstr result))
+ context-depth (if flat-index (1- context-depth) 0)))
+ (setq delim " ")
+ ;; Take care of the indentation:
+ (if flat-index
+ (progn
+ (while flat-index
+ (setq result
+ (cons delim
+ (cons (make-string
+ (1+ (truncate (if (zerop (car flat-index))
+ 1
+ (log10 (car flat-index)))))
+ ? )
+ result)))
+ (setq flat-index (cdr flat-index)))
+ ;; Dispose of single extra delim:
+ (setq result (cdr result))))
+ (apply 'concat result)))
+;;;_ > allout-stringify-flat-index-plain (flat-index)
+(defun allout-stringify-flat-index-plain (flat-index)
+ "Convert list representing section/subsection/... to document string."
+ (let ((delim ".")
+ result)
+ (while flat-index
+ (setq result (cons (int-to-string (car flat-index))
+ (if result
+ (cons delim result))))
+ (setq flat-index (cdr flat-index)))
+ (apply 'concat result)))
+;;;_ > allout-stringify-flat-index-indented (flat-index)
+(defun allout-stringify-flat-index-indented (flat-index)
+ "Convert list representing section/subsection/... to document string."
+ (let ((delim ".")
+ result
+ numstr)
+ ;; Take care of the explicit context:
+ (setq numstr (int-to-string (car flat-index))
+ flat-index (cdr flat-index)
+ result (if flat-index
+ (cons delim (cons numstr result))
+ (cons numstr result)))
+ (setq delim " ")
+ ;; Take care of the indentation:
+ (if flat-index
+ (progn
+ (while flat-index
+ (setq result
+ (cons delim
+ (cons (make-string
+ (1+ (truncate (if (zerop (car flat-index))
+ 1
+ (log10 (car flat-index)))))
+ ? )
+ result)))
+ (setq flat-index (cdr flat-index)))
+ ;; Dispose of single extra delim:
+ (setq result (cdr result))))
+ (apply 'concat result)))
+;;;_ > allout-listify-exposed (&optional start end format)
+(defun allout-listify-exposed (&optional start end format)
+
+ "Produce a list representing exposed topics in current region.
+
+This list can then be used by `allout-process-exposed' to manipulate
+the subject region.
+
+Optional START and END indicate bounds of region.
+
+optional arg, FORMAT, designates an alternate presentation form for
+the prefix:
+
+ list - Present prefix as numeric section.subsection..., starting with
+ section indicated by the list, innermost nesting first.
+ `indent' \(symbol) - Convert header prefixes to all white space,
+ except for distinctive bullets.
+
+The elements of the list produced are lists that represents a topic
+header and body. The elements of that list are:
+
+ - a number representing the depth of the topic,
+ - a string representing the header-prefix, including trailing whitespace and
+ bullet.
+ - a string representing the bullet character,
+ - and a series of strings, each containing one line of the exposed
+ portion of the topic entry."
+
+ (interactive "r")
+ (save-excursion
+ (let*
+ ;; state vars:
+ (strings prefix pad result depth new-depth out gone-out bullet beg
+ next done)
+
+ (goto-char start)
+ (beginning-of-line)
+ ;; Goto initial topic, and register preceeding stuff, if any:
+ (if (> (allout-goto-prefix) start)
+ ;; First topic follows beginning point - register preliminary stuff:
+ (setq result (list (list 0 "" nil
+ (buffer-substring start (1- (point)))))))
+ (while (and (not done)
+ (not (eobp)) ; Loop until we've covered the region.
+ (not (> (point) end)))
+ (setq depth (allout-recent-depth) ; Current topics depth,
+ bullet (allout-recent-bullet) ; ... bullet,
+ prefix (allout-recent-prefix)
+ beg (progn (allout-end-of-prefix t) (point))) ; and beginning.
+ (setq done ; The boundary for the current topic:
+ (not (allout-next-visible-heading 1)))
+ (setq new-depth (allout-recent-depth))
+ (setq gone-out out
+ out (< new-depth depth))
+ (beginning-of-line)
+ (setq next (point))
+ (goto-char beg)
+ (setq strings nil)
+ (while (> next (point)) ; Get all the exposed text in
+ (setq strings
+ (cons (buffer-substring
+ beg
+ ;To hidden text or end of line:
+ (progn
+ (search-forward "\r"
+ (save-excursion (end-of-line)
+ (point))
+ 1)
+ (if (= (preceding-char) ?\r)
+ (1- (point))
+ (point))))
+ strings))
+ (if (< (point) next) ; Resume from after hid text, if any.
+ (forward-line 1))
+ (setq beg (point)))
+ ;; Accumulate list for this topic:
+ (setq strings (nreverse strings))
+ (setq result
+ (cons
+ (if format
+ (let ((special (if (string-match
+ (regexp-quote bullet)
+ allout-distinctive-bullets-string)
+ bullet)))
+ (cond ((listp format)
+ (list depth
+ (if allout-abbreviate-flattened-numbering
+ (allout-stringify-flat-index format
+ gone-out)
+ (allout-stringify-flat-index-plain
+ format))
+ strings
+ special))
+ ((eq format 'indent)
+ (if special
+ (list depth
+ (concat (make-string (1+ depth) ? )
+ (substring prefix -1))
+ strings)
+ (list depth
+ (make-string depth ? )
+ strings)))
+ (t (error "allout-listify-exposed: %s %s"
+ "invalid format" format))))
+ (list depth prefix strings))
+ result))
+ ;; Reasses format, if any:
+ (if (and format (listp format))
+ (cond ((= new-depth depth)
+ (setq format (cons (1+ (car format))
+ (cdr format))))
+ ((> new-depth depth) ; descending - assume by 1:
+ (setq format (cons 1 format)))
+ (t
+ ; Pop the residue:
+ (while (< new-depth depth)
+ (setq format (cdr format))
+ (setq depth (1- depth)))
+ ; And increment the current one:
+ (setq format
+ (cons (1+ (or (car format)
+ -1))
+ (cdr format)))))))
+ ;; Put the list with first at front, to last at back:
+ (nreverse result))))
+;;;_ > my-region-active-p ()
+(defmacro my-region-active-p ()
+ (if (fboundp 'region-active-p)
+ '(region-active-p)
+ 'mark-active))
+;;;_ > allout-process-exposed (&optional func from to frombuf
+;;; tobuf format)
+(defun allout-process-exposed (&optional func from to frombuf tobuf
+ format &optional start-num)
+ "Map function on exposed parts of current topic; results to another buffer.
+
+All args are options; default values itemized below.
+
+Apply FUNCTION to exposed portions FROM position TO position in buffer
+FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
+alternate presentation form:
+
+ `flat' - Present prefix as numeric section.subsection..., starting with
+ section indicated by the start-num, innermost nesting first.
+ X`flat-indented' - Prefix is like `flat' for first topic at each
+ X level, but subsequent topics have only leaf topic
+ X number, padded with blanks to line up with first.
+ `indent' \(symbol) - Convert header prefixes to all white space,
+ except for distinctive bullets.
+
+Defaults:
+ FUNCTION: `allout-insert-listified'
+ FROM: region start, if region active, else start of buffer
+ TO: region end, if region active, else end of buffer
+ FROMBUF: current buffer
+ TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
+ FORMAT: nil"
+
+ ; Resolve arguments,
+ ; defaulting if necessary:
+ (if (not func) (setq func 'allout-insert-listified))
+ (if (not (and from to))
+ (if (my-region-active-p)
+ (setq from (region-beginning) to (region-end))
+ (setq from (point-min) to (point-max))))
+ (if frombuf
+ (if (not (bufferp frombuf))
+ ;; Specified but not a buffer - get it:
+ (let ((got (get-buffer frombuf)))
+ (if (not got)
+ (error (concat "allout-process-exposed: source buffer "
+ frombuf
+ " not found."))
+ (setq frombuf got))))
+ ;; not specified - default it:
+ (setq frombuf (current-buffer)))
+ (if tobuf
+ (if (not (bufferp tobuf))
+ (setq tobuf (get-buffer-create tobuf)))
+ ;; not specified - default it:
+ (setq tobuf (concat "*" (buffer-name frombuf) " exposed*")))
+ (if (listp format)
+ (nreverse format))
+
+ (let* ((listified
+ (progn (set-buffer frombuf)
+ (allout-listify-exposed from to format))))
+ (set-buffer tobuf)
+ (mapcar func listified)
+ (pop-to-buffer tobuf)))
+
+;;;_ - Copy exposed
+;;;_ > allout-insert-listified (listified)
+(defun allout-insert-listified (listified)
+ "Insert contents of listified outline portion in current buffer.
+
+LISTIFIED is a list representing each topic header and body:
+
+ \`(depth prefix text)'
+
+or \`(depth prefix text bullet-plus)'
+
+If `bullet-plus' is specified, it is inserted just after the entire prefix."
+ (setq listified (cdr listified))
+ (let ((prefix (prog1
+ (car listified)
+ (setq listified (cdr listified))))
+ (text (prog1
+ (car listified)
+ (setq listified (cdr listified))))
+ (bullet-plus (car listified)))
+ (insert prefix)
+ (if bullet-plus (insert (concat " " bullet-plus)))
+ (while text
+ (insert (car text))
+ (if (setq text (cdr text))
+ (insert "\n")))
+ (insert "\n")))
+;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
+(defun allout-copy-exposed-to-buffer (&optional arg tobuf format)
+ "Duplicate exposed portions of current outline to another buffer.
+
+Other buffer has current buffers name with \" exposed\" appended to it.
+
+With repeat count, copy the exposed parts of only the current topic.
+
+Optional second arg TOBUF is target buffer name.
+
+Optional third arg FORMAT, if non-nil, symbolically designates an
+alternate presentation format for the outline:
+
+ `flat' - Convert topic header prefixes to numeric
+ section.subsection... identifiers.
+ `indent' - Convert header prefixes to all white space, except for
+ distinctive bullets.
+ `indent-flat' - The best of both - only the first of each level has
+ the full path, the rest have only the section number
+ of the leaf, preceded by the right amount of indentation."
+
+ (interactive "P")
+ (if (not tobuf)
+ (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*"))))
+ (let* ((start-pt (point))
+ (beg (if arg (allout-back-to-current-heading) (point-min)))
+ (end (if arg (allout-end-of-current-subtree) (point-max)))
+ (buf (current-buffer))
+ (start-list ()))
+ (if (eq format 'flat)
+ (setq format (if arg (save-excursion
+ (goto-char beg)
+ (allout-topic-flat-index))
+ '(1))))
+ (save-excursion (set-buffer tobuf)(erase-buffer))
+ (allout-process-exposed 'allout-insert-listified
+ beg
+ end
+ (current-buffer)
+ tobuf
+ format start-list)
+ (goto-char (point-min))
+ (pop-to-buffer buf)
+ (goto-char start-pt)))
+;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf)
+(defun allout-flatten-exposed-to-buffer (&optional arg tobuf)
+ "Present numeric outline of outline's exposed portions in another buffer.
+
+The resulting outline is not compatible with outline mode - use
+`allout-copy-exposed-to-buffer' if you want that.
+
+Use `allout-indented-exposed-to-buffer' for indented presentation.
+
+With repeat count, copy the exposed portions of only current topic.
+
+Other buffer has current buffer's name with \" exposed\" appended to
+it, unless optional second arg TOBUF is specified, in which case it is
+used verbatim."
+ (interactive "P")
+ (allout-copy-exposed-to-buffer arg tobuf 'flat))
+;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf)
+(defun allout-indented-exposed-to-buffer (&optional arg tobuf)
+ "Present indented outline of outline's exposed portions in another buffer.
+
+The resulting outline is not compatible with outline mode - use
+`allout-copy-exposed-to-buffer' if you want that.
+
+Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation.
+
+With repeat count, copy the exposed portions of only current topic.
+
+Other buffer has current buffer's name with \" exposed\" appended to
+it, unless optional second arg TOBUF is specified, in which case it is
+used verbatim."
+ (interactive "P")
+ (allout-copy-exposed-to-buffer arg tobuf 'indent))
+
+;;;_ - LaTeX formatting
+;;;_ > allout-latex-verb-quote (string &optional flow)
+(defun allout-latex-verb-quote (string &optional flow)
+ "Return copy of STRING for literal reproduction across LaTeX processing.
+Expresses the original characters \(including carriage returns) of the
+string across LaTeX processing."
+ (mapconcat (function
+ (lambda (char)
+ (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*))
+ (concat "\\char" (number-to-string char) "{}"))
+ ((= char ?\n) "\\\\")
+ (t (char-to-string char)))))
+ string
+ ""))
+;;;_ > allout-latex-verbatim-quote-curr-line ()
+(defun allout-latex-verbatim-quote-curr-line ()
+ "Express line for exact \(literal) representation across LaTeX processing.
+
+Adjust line contents so it is unaltered \(from the original line)
+across LaTeX processing, within the context of a `verbatim'
+environment. Leaves point at the end of the line."
+ (beginning-of-line)
+ (let ((beg (point))
+ (end (progn (end-of-line)(point))))
+ (goto-char beg)
+ (while (re-search-forward "\\\\"
+ ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
+ end ; bounded by end-of-line
+ 1) ; no matches, move to end & return nil
+ (goto-char (match-beginning 0))
+ (insert "\\")
+ (setq end (1+ end))
+ (goto-char (1+ (match-end 0))))))
+;;;_ > allout-insert-latex-header (buffer)
+(defun allout-insert-latex-header (buffer)
+ "Insert initial LaTeX commands at point in BUFFER."
+ ;; Much of this is being derived from the stuff in appendix of E in
+ ;; the TeXBook, pg 421.
+ (set-buffer buffer)
+ (let ((doc-style (format "\n\\documentstyle{%s}\n"
+ "report"))
+ (page-numbering (if allout-number-pages
+ "\\pagestyle{empty}\n"
+ ""))
+ (linesdef (concat "\\def\\beginlines{"
+ "\\par\\begingroup\\nobreak\\medskip"
+ "\\parindent=0pt\n"
+ " \\kern1pt\\nobreak \\obeylines \\obeyspaces "
+ "\\everypar{\\strut}}\n"
+ "\\def\\endlines{"
+ "\\kern1pt\\endgroup\\medbreak\\noindent}\n"))
+ (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
+ allout-title-style))
+ (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
+ allout-label-style))
+ (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
+ allout-head-line-style))
+ (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
+ allout-body-line-style))
+ (setlength (format "%s%s%s%s"
+ "\\newlength{\\stepsize}\n"
+ "\\setlength{\\stepsize}{"
+ allout-indent
+ "}\n"))
+ (oneheadline (format "%s%s%s%s%s%s%s"
+ "\\newcommand{\\OneHeadLine}[3]{%\n"
+ "\\noindent%\n"
+ "\\hspace*{#2\\stepsize}%\n"
+ "\\labelcmd{#1}\\hspace*{.2cm}"
+ "\\headlinecmd{#3}\\\\["
+ allout-line-skip
+ "]\n}\n"))
+ (onebodyline (format "%s%s%s%s%s%s"
+ "\\newcommand{\\OneBodyLine}[2]{%\n"
+ "\\noindent%\n"
+ "\\hspace*{#1\\stepsize}%\n"
+ "\\bodylinecmd{#2}\\\\["
+ allout-line-skip
+ "]\n}\n"))
+ (begindoc "\\begin{document}\n\\begin{center}\n")
+ (title (format "%s%s%s%s"
+ "\\titlecmd{"
+ (allout-latex-verb-quote (if allout-title
+ (condition-case err
+ (eval allout-title)
+ ('error "<unnamed buffer>"))
+ "Unnamed Outline"))
+ "}\n"
+ "\\end{center}\n\n"))
+ (hsize "\\hsize = 7.5 true in\n")
+ (hoffset "\\hoffset = -1.5 true in\n")
+ (vspace "\\vspace{.1cm}\n\n"))
+ (insert (concat doc-style
+ page-numbering
+ titlecmd
+ labelcmd
+ headlinecmd
+ bodylinecmd
+ setlength
+ oneheadline
+ onebodyline
+ begindoc
+ title
+ hsize
+ hoffset
+ vspace)
+ )))
+;;;_ > allout-insert-latex-trailer (buffer)
+(defun allout-insert-latex-trailer (buffer)
+ "Insert concluding LaTeX commands at point in BUFFER."
+ (set-buffer buffer)
+ (insert "\n\\end{document}\n"))
+;;;_ > allout-latexify-one-item (depth prefix bullet text)
+(defun allout-latexify-one-item (depth prefix bullet text)
+ "Insert LaTeX commands for formatting one outline item.
+
+Args are the topics numeric DEPTH, the header PREFIX lead string, the
+BULLET string, and a list of TEXT strings for the body."
+ (let* ((head-line (if text (car text)))
+ (body-lines (cdr text))
+ (curr-line)
+ body-content bop)
+ ; Do the head line:
+ (insert (concat "\\OneHeadLine{\\verb\1 "
+ (allout-latex-verb-quote bullet)
+ "\1}{"
+ depth
+ "}{\\verb\1 "
+ (if head-line
+ (allout-latex-verb-quote head-line)
+ "")
+ "\1}\n"))
+ (if (not body-lines)
+ nil
+ ;;(insert "\\beginlines\n")
+ (insert "\\begin{verbatim}\n")
+ (while body-lines
+ (setq curr-line (car body-lines))
+ (if (and (not body-content)
+ (not (string-match "^\\s-*$" curr-line)))
+ (setq body-content t))
+ ; Mangle any occurrences of
+ ; "\end{verbatim}" in text,
+ ; it's special:
+ (if (and body-content
+ (setq bop (string-match "\\end{verbatim}" curr-line)))
+ (setq curr-line (concat (substring curr-line 0 bop)
+ ">"
+ (substring curr-line bop))))
+ ;;(insert "|" (car body-lines) "|")
+ (insert curr-line)
+ (allout-latex-verbatim-quote-curr-line)
+ (insert "\n")
+ (setq body-lines (cdr body-lines)))
+ (if body-content
+ (setq body-content nil)
+ (forward-char -1)
+ (insert "\\ ")
+ (forward-char 1))
+ ;;(insert "\\endlines\n")
+ (insert "\\end{verbatim}\n")
+ )))
+;;;_ > allout-latexify-exposed (arg &optional tobuf)
+(defun allout-latexify-exposed (arg &optional tobuf)
+ "Format current topics exposed portions to TOBUF for LaTeX processing.
+TOBUF defaults to a buffer named the same as the current buffer, but
+with \"*\" prepended and \" latex-formed*\" appended.
+
+With repeat count, copy the exposed portions of entire buffer."
+
+ (interactive "P")
+ (if (not tobuf)
+ (setq tobuf
+ (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
+ (let* ((start-pt (point))
+ (beg (if arg (point-min) (allout-back-to-current-heading)))
+ (end (if arg (point-max) (allout-end-of-current-subtree)))
+ (buf (current-buffer)))
+ (set-buffer tobuf)