Giter Club home page Giter Club logo

pkg-octave-doc's Introduction

octave-doc logo

pkg-octave-doc

Create online documentation from Octave help texts (docstrings) of functions and classes in a package, which can be installed with pkg. The generated pages follow the template of the Octave Packages at GitHub Pages based on bootstrap 5 and they have similar layout to the older documentation reference pages at Source Forge. The documentation also includes the demos that are available. Legacy classes (in @class/ folders) are processed as individual functions with separate html pages, classdef files are processed collectively including their public methods in a single html page.

You can find its documentation at https://gnu-octave.github.io/pkg-octave-doc/.

Note that prior to Octave 9.1, the methods function used internally to derive the available methods of a class does not differentiate between public and private methods, hence all methods are listed. As a result, any method in the classdef that has a valid texinfo docstring will be included in the generated HTML documentation. Moreover, the get_help_text function does not return the help docstring from the classdef's method when it shadows a parent method derived from a superclass which the classdef is derived from. See bug #65220 for more information. As a workaround, pkg-octave-doc (>=0.5.3), parses the texinfo docstrings directly from the classdef file. As a result, parent methods that are not documented in the classdef will not be included in the generated HTML documentation.

Requirements

  • The function function_texi2html relies on the texi2html v1.82 software which must be installed and available to $PATH.

  • If curl and tar are installed and available to $PATH, and an internet connection are available, the functions' generated pages also include a URL to their respective repository locations. This feature is only available for packages hosted at GitHub.

Installation

To install the latest version (0.5.5) you need Octave (>=7.2.0) installed on your system. You can install it by typing:

pkg install -forge pkg-octave-doc

To install the latest development version type:

pkg install "https://github.com/gnu-octave/pkg-octave-doc/archive/refs/heads/main.zip"

Usage

Generate a function reference for all functions listed in the INDEX file of an installed Octave package in the working directory:

package_texi2html ("pkg-octave-doc")

If you wish to host the generated documentation on GitHub Pages, you need to create a /docs folder at the root of your package's repository hosted at Github (or at least mirrored there), run the above command from inside this folder in Octave to generate all necessary files, push the changes and from the repository's interface at GitHub, go to settings, choose Pages on the left hand side list (last item in the Code and automation category), and in the Build and deployment section of the GitHub Pages select:

Source -> Deploy from a branch

Branch -> main /docs and click Save.

You only need to do this once, and the package's website will be automatically updated every time you push a new commit into the package's /docs folder.

Guidelines for TEXIFNO docsstrings

  • @qcode is converted to @code before texi2html processing, so if you want to display a char string it is best to use @qcode{"somestring"}, which will be displayed properly both on Octave's command window and on HTML output. Keep in mind that @code{} encloses the content in single quotes in the command window, although they are not displayed in HTML code.

  • fields of structures: it is best practice to write them as @var{structure_name}.@qcode{field_name} which appears in the command window as structure_name.field_name and in HTML as structure_name.field_name. In bootstrap 5, the <code> tag is not highlighted and it looks better than here ๐Ÿ˜ƒ.

  • Avoid nesting @itemize and @multitable blocks because they are not parsed correctly by texi2html. You can achieve the same visual result by segmenting them.

  • Table columns in HTML use dynamic width, so if you wish to maintain the required width for better visualization, add extra empty @tags inbetween.

For example:

@multitable @columnfractions 0.35 0.65
@item text @tab text

can be converted to

@multitable @columnfractions 0.33 0.02 0.65
@item text @tab @tab text
  • Make sure that @deftypefn and @deftypefnx tags have a space before them. This is especially important for help strings in oct files (in .cc code) where we don't use ## for initiating a comment line. For example:

in .m files

## -*- texinfo -*-
## @deftypefn  {pkg-octave-doc} {} function_texi2html (@var{fcnname}, @var{pkgfcns}, @var{info})
##

in .oct files

DEFUN_DLD (libsvmread, args, nargout,
           "-*- texinfo -*- \n\n\
 @deftypefn  {statistics} {[@var{labels}, @var{data}] =} libsvmread (@var{filename})\n\
\n\
\n\
This function ...
  • Small docstrings containing a single line of help text after the @deftypefn tag must have an additional empty line before @end deftypefn in order to be parsed correclty. For example, the following docstring
## -*- texinfo -*-
## @deftypefn {RTree} {@var{n} =} rect_size ()
##
## The size @var{n} in bytes of a rectangle.
## @end deftypefn

must be

## -*- texinfo -*-
## @deftypefn {RTree} {@var{n} =} rect_size ()
##
## The size @var{n} in bytes of a rectangle.
##
## @end deftypefn

in order to be properly formatted in final HTML code.

  • @math{} texi tags are converted to <math></math> tags in HTML and their contents are scanned for x and * characters, which are replaced by &times; in order to properly display the multiplication symbol. Make sure that lower case x within the @math{} tags is explicitly used for denoting multiplication and it is not used for anything else (e.g. variable name). This feature, introduced in release 0.4.7, only affects the contents of @math{} texi tags.

  • At the moment, function_texi2html can handle a signle @seealso{} tag. Make sure that there is only one @seealso{} tag inside each function's docstring located at the very end just before the @end deftypefn texinfo closing statement. Functions listed therein that belong to the same package are also linked to their individual function pages.

  • @tex tags must only contain latex mathematical expressions enclosed with $$ identifiers, such as in $$ ... $$. Math delimiters \(...\) are also processed in @tex blocks.

TODO

  1. Write a C++ implementation for parsing texinfo to html to relax the dependency on the rather outdated texi2html software.
  2. Rewrite build_DEMOS function so that DEMO documentation includes the console output and generated figures just after the line of code that produces the output instead of accumulating all the output and figures after the DEMO code block. This should help larger DEMO blocks to be more intuitively presented in the generated documentation.

Further notes

Albeit completely overhauled, this is a fork of the generate_html package previously used for Source Forge reference pages.

pkg-octave-doc's People

Contributors

carandraug avatar cbm755 avatar i7tiol avatar jbect avatar oheim avatar pr0m1th3as avatar siko1056 avatar trucomanx avatar ttl-octave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pkg-octave-doc's Issues

error: bd_tag(1): out of bound 0 (dimensions are 0x0)

>>> package_texi2html("pkg-octave-doc")
error: bd_tag(1): out of bound 0 (dimensions are 0x0)
error: called from
    function_texi2html at line 148 column 29
    package_texi2html at line 268 column 7

And I got the same error for other packages I tried (doctest, image, symbolic).

OS is Fedora 37, Octave 7.2.0, texi2html installed from Fedora package:

$ texi2html --version
5.0

reliably trimming the "generated on <date> using <blah>"

Is this code supposed to find the "real body" of the output, stripping the "generated on blah by blah"?

    ## Remove content before <body> tag and after <hr size="1">
    txt_beg = strfind (fcn_text, "<body ");
    txt_end = strfind (fcn_text, "<hr size=""1"">") - 1;
    fcn_text = fcn_text([txt_beg:txt_end]);

Using texi2html 5.0 from Fedora (see also #5), I have:

<p> @seealso{function_texi2html, find_GHurls, build_DEMOS}
 </p></dd></dl>
<hr>
<p>
 <font size="-1">
  This document was generated on <i>February 21, 2023</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 5.0</i></a>.
 </font>
 <br>

</p>
</body>
</html>

I tried this and it seems to work:

    txt_end = strfind (fcn_text, "<hr>\n<p>\n <font size=""-1"">") - 1

But this all feels a bit fragile... version-specific...

Did you see an option in texi2html to suppress that that output?

Improve error message when texi2html is missing

From this:

package_texi2html("doctest")
error: function_texi2html: unable to convert to html.
error: called from
    function_texi2html at line 132 column 5
    package_texi2html at line 268 column 7

and the README, I was able to guess what was wrong, but maybe it could give a clear error message.

Perhaps "texi2html command-line tool is missing, see documentation"?

Odd formatting for "small" descriptions

Hi!

I've been setting-up getting the documentation for a package of mine with GitLab pages (similar to the Github version). That's now building, using the latest Octave and pkg-octave-doc from -forge. Those generated docs are here. For the methods with substantial documentation, the results look fine: RTree.csv_read for example. But for the those with minimal documentation something is awry. The rect_size instance method has source

    ## -*- texinfo -*-
    ## @deftypefn {RTree} {@var{n} =} rect_size ()
    ##
    ## The size @var{n} in bytes of a rectangle.
    ## @end deftypefn

    function val = rect_size(obj)
      val = RTree_dispatch('rect_size', obj.state);
    endfunction

producing

Screenshot from 2024-01-22 23-19-07

with the html being

<dl>
<dt><u>RTree:</u> <var>n</var> = <b>rect_size</b><i> ()</i></dt>
</dl>

<p> The size <var>n</var> in bytes of a rectangle.
 </p><<div class="ms-5">
/dd></dl>

as here.

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.