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> [<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>, …)</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>, …)</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 <https://www.octave.org link to *GNU Octave*>.
##
# "Real" 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 ("pub_example.m")</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> ‘<samp>format</samp>’ — Output format of the published script file, one of
<p>‘<samp>html</samp>’ (default), ‘<samp>doc</samp>’, ‘<samp>latex</samp>’, ‘<samp>ppt</samp>’,
‘<samp>pdf</samp>’, or ‘<samp>xml</samp>’.
</p>
<p>The output formats ‘<samp>doc</samp>’, ‘<samp>ppt</samp>’, and ‘<samp>xml</samp>’ are not currently
supported. To generate a ‘<samp>doc</samp>’ report, open a generated ‘<samp>html</samp>’
report with your office suite.
</p>
<p>In Octave custom formats are supported by implementing all callback
subfunctions in a function file named
‘<samp>__publish_<custom format>_output__.m</samp>’. To obtain a template for the
HTML format type:
</p>
<div class="example">
<pre class="example">edit (fullfile (fileparts (which ("publish")), ...
"private", "__publish_html_output__.m"))
</pre></div>
</li><li> ‘<samp>outputDir</samp>’ — 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> ‘<samp>stylesheet</samp>’ — Not supported, only for <small>MATLAB</small> compatibility.
</li><li> ‘<samp>createThumbnail</samp>’ — Not supported, only for <small>MATLAB</small>
compatibility.
</li><li> ‘<samp>figureSnapMethod</samp>’ — Not supported, only for <small>MATLAB</small>
compatibility.
</li><li> ‘<samp>imageFormat</samp>’ — Desired format for any images produced while
evaluating the code. The allowed image formats depend on the output format:
<ul>
<li> ‘<samp>html</samp>’, ‘<samp>xml</samp>’ — ‘<samp>png</samp>’ (default), any image format
supported by Octave
</li><li> ‘<samp>latex</samp>’ — ‘<samp>epsc2</samp>’ (default), any image format supported by
Octave
</li><li> ‘<samp>pdf</samp>’ — ‘<samp>jpg</samp>’ (default) or ‘<samp>bmp</samp>’, note <small>MATLAB</small>
uses ‘<samp>bmp</samp>’ as default
</li><li> ‘<samp>doc</samp>’ or ‘<samp>ppt</samp>’ — ‘<samp>png</samp>’ (default), ‘<samp>jpg</samp>’,
‘<samp>bmp</samp>’, or ‘<samp>tiff</samp>’
</li></ul>
</li><li> ‘<samp>maxWidth</samp>’ and ‘<samp>maxHeight</samp>’ — 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>‘<samp>[]</samp>’ (default), integer value ≥ 0
</p>
</li><li> ‘<samp>useNewFigure</samp>’ — Use a new figure window for figures created by the
evaluated code. This avoids side effects with already opened figure
windows.
<p>‘<samp>true</samp>’ (default) or ‘<samp>false</samp>’
</p>
</li><li> ‘<samp>evalCode</samp>’ — Evaluate code of the Octave source file
<p>‘<samp>true</samp>’ (default) or ‘<samp>false</samp>’
</p>
</li><li> ‘<samp>catchError</samp>’ — Catch errors while evaluating code and continue
<p>‘<samp>true</samp>’ (default) or ‘<samp>false</samp>’
</p>
</li><li> ‘<samp>codeToEvaluate</samp>’ — Octave commands that should be evaluated prior to
publishing the script file. These Octave commands do not appear in the
generated report.
</li><li> ‘<samp>maxOutputLines</samp>’ — Maximum number of output lines from code
evaluation which are included in output.
<p>‘<samp>Inf</samp>’ (default) or integer value > 0
</p>
</li><li> ‘<samp>showCode</samp>’ — Show the evaluated Octave commands in the generated
report
<p>‘<samp>true</samp>’ (default) or ‘<samp>false</samp>’
</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>(…)</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 ‘<samp>##### SOURCE BEGIN #####</samp>’ and ‘<samp>##### SOURCE END #####</samp>’.
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 ("my_script.m");
grabcode ("html/my_script.html");
</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> [<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>
|