annotate scripts/miscellaneous/private/__publish_latex_output__.m @ 30242:33d895260fa4

publish.m: Support some non-ASCII characters in comments for pdf output. * scripts/miscellaneous/publish.m: Clarify documentation. Publishing Markup is only interpreted in section comments. Remove sentence that suggests that commands in the output format might be interpreted in that format. * scripts/miscellaneous/private/__publish_latex_output__.m: Add substitution rules for some multi-byte UTF-8 characters (mostly Latin-based) to LaTeX publish template. This fixes a bug where using these characters in comments would cause `pdflatex` to fail. See: https://github.com/gnu-octave/octave/pull/5
author Markus Mützel <markus.muetzel@gmx.de>
date Sun, 17 Oct 2021 12:28:51 +0200
parents 0a5b15007766
children 363fb10055df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
3 ## Copyright (C) 2016-2021 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
7 ##
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
8 ## This file is part of Octave.
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24491
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24491
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
13 ## (at your option) any later version.
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
14 ##
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
18 ## GNU General Public License for more details.
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
19 ##
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
20 ## You should have received a copy of the GNU General Public License
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24491
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
25
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
26 ## -*- texinfo -*-
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
27 ## @deftypefn {} {@var{outstr} =} __publish_latex_output__ (@var{type}, @var{varargin})
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
28 ##
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
29 ## Internal function.
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
30 ##
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
31 ## The first input argument @var{type} defines the required strings
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
32 ## (@samp{str}) or cell-strings (@samp{cstr}) in @var{varargin} in order
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
33 ## to produce @LaTeX{} output.
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
34 ##
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
35 ## @var{type} is one of
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
36 ##
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
37 ## @itemize @bullet
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
38 ## @item
23188
e2e182a8e699 Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23086
diff changeset
39 ## @samp{output_file_extension} ()
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
40 ##
23188
e2e182a8e699 Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23086
diff changeset
41 ## @item
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
42 ## @samp{header} (title_str, intro_str, toc_cstr)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
43 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
44 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
45 ## @samp{footer} ()
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
46 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
47 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
48 ## @samp{code} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
49 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
50 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
51 ## @samp{code_output} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
52 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
53 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
54 ## @samp{section} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
55 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
56 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
57 ## @samp{preformatted_code} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
58 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
59 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
60 ## @samp{preformatted_text} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
61 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
62 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
63 ## @samp{bulleted_list} (cstr)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
64 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
65 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
66 ## @samp{numbered_list} (cstr)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
67 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
68 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
69 ## @samp{graphic} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
70 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
71 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
72 ## @samp{html} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
73 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
74 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
75 ## @samp{latex} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
76 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
77 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
78 ## @samp{text} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
79 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
80 ## @item
23923
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
81 ## @samp{blockmath} (str)
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
82 ##
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
83 ## @item
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
84 ## @samp{inlinemath} (str)
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
85 ##
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
86 ## @item
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
87 ## @samp{bold} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
88 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
89 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
90 ## @samp{italic} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
91 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
92 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
93 ## @samp{monospaced} (str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
94 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
95 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
96 ## @samp{link} (url_str, url_str, str)
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
97 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
98 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
99 ## @samp{TM} ()
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23188
diff changeset
100 ##
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
101 ## @item
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
102 ## @samp{R} ()
23964
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
103 ##
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
104 ## @item
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
105 ## @samp{escape_special_chars} (str)
22781
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
106 ## @end itemize
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
107 ## @end deftypefn
449a5e84185a doc: Add copyright notice and improve docstring.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 22705
diff changeset
108
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
109 function outstr = __publish_latex_output__ (type, varargin)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
110 outstr = feval (["do_" type], varargin{:});
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
111 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
112
23188
e2e182a8e699 Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23086
diff changeset
113 function outstr = do_output_file_extension ()
e2e182a8e699 Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23086
diff changeset
114 outstr = ".tex";
e2e182a8e699 Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23086
diff changeset
115 endfunction
e2e182a8e699 Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23086
diff changeset
116
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
117 function outstr = do_header (title_str, intro_str, toc_cstr)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
118 publish_comment = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
119 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
120 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
121 "% This document was generated by the publish-function",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
122 ["% from GNU Octave " version()],
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
123 "");
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
124
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
125 latex_preamble = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
126 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
127 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
128 '\documentclass[10pt]{article}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
129 '\usepackage{listings}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
130 '\usepackage{mathtools}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
131 '\usepackage{amssymb}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
132 '\usepackage{graphicx}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
133 '\usepackage{hyperref}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
134 '\usepackage{xcolor}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
135 '\usepackage{titlesec}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
136 '\usepackage[utf8]{inputenc}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
137 '\usepackage[T1]{fontenc}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
138 '\usepackage{lmodern}');
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
139
30242
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
140 # "lstlisting" doesn't support multi-byte UTF-8 characters.
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
141 # Add substitution rules for some characters (commonly used in languages with
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
142 # Latin-based script).
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
143 # Set of substitions taken from:
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
144 # https://en.wikibooks.org/w/index.php?title=LaTeX/Source_Code_Listings&oldid=3815132#Encoding_issue
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
145 # FIXME: Any multi-byte UTF-8 character in a non-section comment without a
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
146 # substitution rule will still cause an error. This should be fixed
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
147 # more generally, or a way how to work around this limitation should
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
148 # be documented.
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
149 listings_option = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
150 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
151 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
152 '\lstset{',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
153 'language=Octave,',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
154 'numbers=none,',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
155 'frame=single,',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
156 'tabsize=2,',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
157 'showstringspaces=false,',
30242
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
158 'breaklines=true,',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
159 'inputencoding=utf8,',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
160 'extendedchars=true,',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
161 'literate=',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
162 ' {á}{{\''a}}1 {é}{{\''e}}1 {í}{{\''i}}1 {ó}{{\''o}}1 {ú}{{\''u}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
163 ' {Á}{{\''A}}1 {É}{{\''E}}1 {Í}{{\''I}}1 {Ó}{{\''O}}1 {Ú}{{\''U}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
164 ' {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
165 ' {À}{{\`A}}1 {È}{{\''E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
166 ' {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
167 ' {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
168 ' {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
169 ' {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
170 ' {ã}{{\~a}}1 {}{{\~e}}1 {ĩ}{{\~i}}1 {õ}{{\~o}}1 {ũ}{{\~u}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
171 ' {Ã}{{\~A}}1 {}{{\~E}}1 {Ĩ}{{\~I}}1 {Õ}{{\~O}}1 {Ũ}{{\~U}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
172 ' {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
173 ' {ű}{{\H{u}}}1 {Ű}{{\H{U}}}1 {ő}{{\H{o}}}1 {Ő}{{\H{O}}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
174 ' {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
175 ' {}{{\euro}}1 {£}{{\pounds}}1 {«}{{\guillemotleft}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
176 ' {»}{{\guillemotright}}1 {ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1 {¡}{{!`}}1',
33d895260fa4 publish.m: Support some non-ASCII characters in comments for pdf output.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29358
diff changeset
177 '}');
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
178
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
179 latex_head = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
180 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
181 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
182 '\titleformat*{\section}{\Huge\bfseries}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
183 '\titleformat*{\subsection}{\large\bfseries}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
184 '\renewcommand{\contentsname}{\Large\bfseries Contents}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
185 '\setlength{\parindent}{0pt}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
186 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
187 '\begin{document}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
188 "",
23964
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
189 ['{\Huge\section*{' title_str '}}'],
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
190 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
191 '\tableofcontents',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
192 '\vspace*{4em}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
193 "");
22157
c5842206aaea maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22113
diff changeset
194
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
195 outstr = [publish_comment, latex_preamble, listings_option, latex_head];
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
196
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
197 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
198
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
199 function outstr = do_footer (m_source_str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
200 outstr = ["\n\n" '\end{document}' "\n"];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
201 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
202
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
203 function outstr = do_code (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
204 outstr = ['\begin{lstlisting}' "\n", str, "\n" '\end{lstlisting}' "\n"];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
205 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
206
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
207 function outstr = do_code_output (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
208 outstr = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
209 '\begin{lstlisting}[language={},xleftmargin=5pt,frame=none]',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
210 str,
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
211 '\end{lstlisting}');
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
212 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
213
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
214 function outstr = do_section (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
215 outstr = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
216 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
217 "",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
218 '\phantomsection',
23964
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
219 ['\addcontentsline{toc}{section}{' str '}'],
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
220 ['\subsection*{' str '}'],
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
221 "");
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
222 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
223
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
224 function outstr = do_preformatted_code (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
225 outstr = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
226 '\begin{lstlisting}',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
227 str,
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
228 '\end{lstlisting}');
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
229 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
230
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
231 function outstr = do_preformatted_text (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
232 outstr = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
233 '\begin{lstlisting}[language={}]',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
234 str,
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
235 '\end{lstlisting}');
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
236 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
237
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
238 function outstr = do_bulleted_list (cstr)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
239 outstr = ["\n" '\begin{itemize}' "\n"];
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
240 for i = 1:numel (cstr)
23964
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
241 outstr = [outstr, '\item ' cstr{i} "\n"];
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
242 endfor
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
243 outstr = [outstr, '\end{itemize}' "\n"];
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
244 endfunction
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
245
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
246 function outstr = do_numbered_list (cstr)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
247 outstr = ["\n" '\begin{enumerate}' "\n"];
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
248 for i = 1:numel (cstr)
23964
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
249 outstr = [outstr, '\item ' cstr{i} "\n"];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
250 endfor
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
251 outstr = [outstr, "\\end{enumerate}\n"];
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
252 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
253
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
254 function outstr = do_graphic (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
255 outstr = sprintf ("%s\n",
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
256 '\begin{figure}[!ht]',
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
257 ['\includegraphics[width=\textwidth]{' str '}'],
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
258 '\end{figure}');
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
259 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
260
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
261 function outstr = do_html (str)
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
262 outstr = "";
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
263 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
264
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
265 function outstr = do_latex (str)
23926
58b76c741c3d publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23923
diff changeset
266 outstr = ["\n" str "\n"];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
267 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
268
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
269 function outstr = do_link (url_str, str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
270 outstr = ['\href{' url_str '}{' str '}'];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
271 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
272
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
273 function outstr = do_text (str)
23964
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
274 outstr = ["\n\n" str "\n\n"];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
275 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
276
23923
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
277 function outstr = do_blockmath (str)
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
278 outstr = ["$$" str "$$"];
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
279 endfunction
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
280
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
281 function outstr = do_inlinemath (str)
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
282 outstr = ["$" str "$"];
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
283 endfunction
62dc81691d73 publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23565
diff changeset
284
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
285 function outstr = do_bold (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
286 outstr = ['\textbf{' str '}'];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
287 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
288
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
289 function outstr = do_italic (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
290 outstr = ['\textit{' str '}'];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
291 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
292
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
293 function outstr = do_monospaced (str)
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
294 outstr = ['\texttt{' str '}'];
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
295 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
296
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
297 function outstr = do_TM ()
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
298 outstr = '\texttrademark ';
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
299 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
300
22705
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
301 function outstr = do_R ()
e9a0aa0a49ed Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents: 22384
diff changeset
302 outstr = '\textregistered ';
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
303 endfunction
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
304
23964
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
305 function str = do_escape_special_chars (str)
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
306 ## Escape \, {, }, &, %, #, _, ~, ^, <, >
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
307 str = regexprep (str, '\\', "\\ensuremath{\\backslash}");
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
308 str = regexprep (str, '(?<!\\)(\{|\}|&|%|#|_)', '\\$1');
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
309 ## Revert accidental {} replacements for backslashes
23964
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
310 str = strrep (str, '\ensuremath\{\backslash\}', '\ensuremath{\backslash}');
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
311 str = regexprep (str, '(?<!\\)~', "\\ensuremath{\\tilde{\\;}}");
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
312 str = regexprep (str, '(?<!\\)\^', "\\^{}");
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
313 str = regexprep (str, '(?<!\\)<', "\\ensuremath{<}");
1a0cbb573a67 publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23926
diff changeset
314 str = regexprep (str, '(?<!\\)>', "\\ensuremath{>}");
22113
b6f482e29afd New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
315 endfunction