File: Publish-Octave-Script-Files.html

package info (click to toggle)
octave 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 124,192 kB
  • sloc: cpp: 322,665; ansic: 68,088; fortran: 20,980; objc: 8,121; sh: 7,719; yacc: 4,266; lex: 4,123; perl: 1,530; java: 1,366; awk: 1,257; makefile: 424; xml: 147
file content (255 lines) | stat: -rw-r--r-- 11,497 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Publish Octave Script Files (GNU Octave (version 6.2.0))</title>

<meta name="description" content="Publish Octave Script Files (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Publish Octave Script Files (GNU Octave (version 6.2.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Script-Files.html" rel="up" title="Script Files">
<link href="Publishing-Markup.html" rel="next" title="Publishing Markup">
<link href="Script-Files.html" rel="prev" title="Script Files">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<span id="Publish-Octave-Script-Files"></span><div class="header">
<p>
Next: <a href="Publishing-Markup.html" accesskey="n" rel="next">Publishing Markup</a>, Up: <a href="Script-Files.html" accesskey="u" rel="up">Script Files</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Publish-Octave-Script-Files-1"></span><h4 class="subsection">11.11.1 Publish Octave Script Files</h4>

<p>The function <code>publish</code> provides a dynamic possibility to document your
script file.  Unlike static documentation, <code>publish</code> runs the script
file, saves any figures and output while running the script, and presents them
alongside static documentation in a desired output format.  The static
documentation can make use of <a href="Publishing-Markup.html">Publishing Markup</a> to enhance and
customize the output.
</p>
<span id="XREFpublish"></span><dl>
<dt id="index-publish">: <em></em> <strong>publish</strong> <em>(<var>file</var>)</em></dt>
<dt id="index-publish-1">: <em></em> <strong>publish</strong> <em>(<var>file</var>, <var>output_format</var>)</em></dt>
<dt id="index-publish-2">: <em></em> <strong>publish</strong> <em>(<var>file</var>, <var>option1</var>, <var>value1</var>, &hellip;)</em></dt>
<dt id="index-publish-3">: <em></em> <strong>publish</strong> <em>(<var>file</var>, <var>options</var>)</em></dt>
<dt id="index-publish-4">: <em><var>output_file</var> =</em> <strong>publish</strong> <em>(<var>file</var>, &hellip;)</em></dt>
<dd>
<p>Generate a report from the Octave script file <var>file</var> in one of several
output formats.
</p>
<p>The generated reports interpret any Publishing Markup in comments, which is
explained in detail in the GNU Octave manual.  Assume the following example,
using some Publishing Markup, to be the contents of the script file
<samp>pub_example.m</samp>:
</p>
<div class="example">
<pre class="example">## Headline title
#
# Some *bold*, _italic_, or |monospaced| Text with
# a &lt;https://www.octave.org link to *GNU Octave*&gt;.
##

# &quot;Real&quot; Octave commands to be evaluated
sombrero ()

%% MATLAB comment style ('%') is supported as well
%
% * Bulleted list item 1
% * Bulleted list item 2
%
% # Numbered list item 1
% # Numbered list item 2
</pre></div>

<p>To publish this script file, type <code>publish (&quot;pub_example.m&quot;)</code>.
</p>
<p>With only <var>file</var> given, a HTML report is generated in a subdirectory
<samp>html</samp> relative to the current working directory.  The Octave commands
are evaluated in a separate context and any figures created while executing
the script file are included in the report.  All formatting syntax of
<var>file</var> is treated according to the specified output format and included
in the report.
</p>
<p>Using <code>publish (<var>file</var>, <var>output_format</var>)</code> is equivalent to the
function call using a structure
</p>
<div class="example">
<pre class="example"><var>options</var>.format = <var>output_format</var>;
publish (<var>file</var>, <var>options</var>)
</pre></div>

<p>which is described below.  The same holds for using option/value pairs
</p>
<div class="example">
<pre class="example"><var>options</var>.<var>option1</var> = <var>value1</var>;
publish (<var>file</var>, <var>options</var>)
</pre></div>

<p>The structure <var>options</var> can have the following field names.  If a field
name is not specified, the default value is used:
</p>
<ul>
<li> &lsquo;<samp>format</samp>&rsquo; &mdash; Output format of the published script file, one of

<p>&lsquo;<samp>html</samp>&rsquo; (default), &lsquo;<samp>doc</samp>&rsquo;, &lsquo;<samp>latex</samp>&rsquo;, &lsquo;<samp>ppt</samp>&rsquo;,
&lsquo;<samp>pdf</samp>&rsquo;, or &lsquo;<samp>xml</samp>&rsquo;.
</p>
<p>The output formats &lsquo;<samp>doc</samp>&rsquo;, &lsquo;<samp>ppt</samp>&rsquo;, and &lsquo;<samp>xml</samp>&rsquo; are not currently
supported.  To generate a &lsquo;<samp>doc</samp>&rsquo; report, open a generated &lsquo;<samp>html</samp>&rsquo;
report with your office suite.
</p>
<p>In Octave custom formats are supported by implementing all callback
subfunctions in a function file named
&lsquo;<samp>__publish_&lt;custom format&gt;_output__.m</samp>&rsquo;.  To obtain a template for the
HTML format type:
</p>
<div class="example">
<pre class="example">edit (fullfile (fileparts (which (&quot;publish&quot;)), ...
      &quot;private&quot;, &quot;__publish_html_output__.m&quot;))
</pre></div>

</li><li> &lsquo;<samp>outputDir</samp>&rsquo; &mdash; Full path of the directory where the generated report
will be located.  If no directory is given, the report is generated in a
subdirectory <samp>html</samp> relative to the current working directory.

</li><li> &lsquo;<samp>stylesheet</samp>&rsquo; &mdash; Not supported, only for <small>MATLAB</small> compatibility.

</li><li> &lsquo;<samp>createThumbnail</samp>&rsquo; &mdash; Not supported, only for <small>MATLAB</small>
compatibility.

</li><li> &lsquo;<samp>figureSnapMethod</samp>&rsquo; &mdash; Not supported, only for <small>MATLAB</small>
compatibility.

</li><li> &lsquo;<samp>imageFormat</samp>&rsquo; &mdash; Desired format for any images produced while
evaluating the code.  The allowed image formats depend on the output format:

<ul>
<li> &lsquo;<samp>html</samp>&rsquo;, &lsquo;<samp>xml</samp>&rsquo; &mdash; &lsquo;<samp>png</samp>&rsquo; (default), any image format
supported by Octave

</li><li> &lsquo;<samp>latex</samp>&rsquo; &mdash; &lsquo;<samp>epsc2</samp>&rsquo; (default), any image format supported by
Octave

</li><li> &lsquo;<samp>pdf</samp>&rsquo; &mdash; &lsquo;<samp>jpg</samp>&rsquo; (default) or &lsquo;<samp>bmp</samp>&rsquo;, note <small>MATLAB</small>
uses  &lsquo;<samp>bmp</samp>&rsquo; as default

</li><li> &lsquo;<samp>doc</samp>&rsquo; or &lsquo;<samp>ppt</samp>&rsquo; &mdash; &lsquo;<samp>png</samp>&rsquo; (default), &lsquo;<samp>jpg</samp>&rsquo;,
&lsquo;<samp>bmp</samp>&rsquo;, or &lsquo;<samp>tiff</samp>&rsquo;
</li></ul>

</li><li> &lsquo;<samp>maxWidth</samp>&rsquo; and &lsquo;<samp>maxHeight</samp>&rsquo; &mdash; Maximum width (height) of the
produced images in pixels.  An empty value means no restriction.  Both
values must be set in order for the option to work properly.

<p>&lsquo;<samp>[]</samp>&rsquo; (default), integer value &ge; 0
</p>
</li><li> &lsquo;<samp>useNewFigure</samp>&rsquo; &mdash; Use a new figure window for figures created by the
evaluated code.  This avoids side effects with already opened figure
windows.

<p>&lsquo;<samp>true</samp>&rsquo; (default) or &lsquo;<samp>false</samp>&rsquo;
</p>
</li><li> &lsquo;<samp>evalCode</samp>&rsquo; &mdash; Evaluate code of the Octave source file

<p>&lsquo;<samp>true</samp>&rsquo; (default) or &lsquo;<samp>false</samp>&rsquo;
</p>
</li><li> &lsquo;<samp>catchError</samp>&rsquo; &mdash; Catch errors while evaluating code and continue

<p>&lsquo;<samp>true</samp>&rsquo; (default) or &lsquo;<samp>false</samp>&rsquo;
</p>
</li><li> &lsquo;<samp>codeToEvaluate</samp>&rsquo; &mdash; Octave commands that should be evaluated prior to
publishing the script file.  These Octave commands do not appear in the
generated report.

</li><li> &lsquo;<samp>maxOutputLines</samp>&rsquo; &mdash; Maximum number of output lines from code
evaluation which are included in output.

<p>&lsquo;<samp>Inf</samp>&rsquo; (default) or integer value &gt; 0
</p>
</li><li> &lsquo;<samp>showCode</samp>&rsquo; &mdash; Show the evaluated Octave commands in the generated
report

<p>&lsquo;<samp>true</samp>&rsquo; (default) or &lsquo;<samp>false</samp>&rsquo;
</p></li></ul>

<p>The option output <var>output_file</var> is a string with path and file name
of the generated report.
</p>

<p><strong>See also:</strong> <a href="#XREFgrabcode">grabcode</a>.
</p></dd></dl>


<p>The counterpart to <code>publish</code> is <code>grabcode</code>:
</p>
<span id="XREFgrabcode"></span><dl>
<dt id="index-grabcode">: <em></em> <strong>grabcode</strong> <em>(<var>url</var>)</em></dt>
<dt id="index-grabcode-1">: <em></em> <strong>grabcode</strong> <em>(<var>filename</var>)</em></dt>
<dt id="index-grabcode-2">: <em><var>code_str</var> =</em> <strong>grabcode</strong> <em>(&hellip;)</em></dt>
<dd>
<p>Grab the code from a report created by the <code>publish</code> function.
</p>
<p>The grabbed code inside the published report must be enclosed by the
strings &lsquo;<samp>##### SOURCE BEGIN #####</samp>&rsquo; and &lsquo;<samp>##### SOURCE END #####</samp>&rsquo;.
The <code>publish</code> function creates this format automatically.
</p>
<p>If no return value is requested the code is saved to a temporary file and
opened in the default editor.  NOTE: The temporary file must be saved under
a new or the code will be lost.
</p>
<p>If an output is requested the grabbed code will be returned as string
<var>code_str</var>.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">publish (&quot;my_script.m&quot;);
grabcode (&quot;html/my_script.html&quot;);
</pre></div>

<p>The example above publishes <samp>my_script.m</samp> to the default location
<samp>html/my_script.html</samp>.  Next, the published Octave script is grabbed to
edit its content in a new temporary file.
</p>

<p><strong>See also:</strong> <a href="#XREFpublish">publish</a>.
</p></dd></dl>


<hr>
<div class="header">
<p>
Next: <a href="Publishing-Markup.html" accesskey="n" rel="next">Publishing Markup</a>, Up: <a href="Script-Files.html" accesskey="u" rel="up">Script Files</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>