++ed by:
Marco Pessotto
and 1 contributors

# NAME

Text::Amuse::Output - Internal module for Text::Amuse output

# SYNOPSIS

The module is used internally by Text::Amuse, so everything here is pretty much internal only (and underdocumented).

## Basic LaTeX preamble

  \documentclass[DIV=9,fontsize=10pt,oneside,paper=a5]{scrbook}
\usepackage{graphicx}
\usepackage{alltt}
\usepackage{verbatim}
\usepackage{bookmark}
\usepackage[stable]{footmisc}
\usepackage{enumerate}
\usepackage{longtable}
\usepackage[normalem]{ulem}
\usepackage{wrapfig}

% avoid breakage on multiple <br><br> and avoid the next [] to be eaten
\newcommand*{\forcelinebreak}{~\\\relax}
% this also works
% \newcommand*{\forcelinebreak}{\strut\\{}}

\newcommand*{\hairline}{%
\bigskip%
\noindent \hrulefill%
\bigskip%
}

% reverse indentation for biblio and play

\newenvironment{amusebiblio}{
\leftskip=\parindent
\parindent=-\parindent
\bigskip
\indent
}{\bigskip}

\newenvironment{amuseplay}{
\leftskip=\parindent
\parindent=-\parindent
\bigskip
\indent
}{\bigskip}

\newcommand{\Slash}{\slash\hspace{0pt}}

Text::Amuse::Output->new(document => $obj, format => "ltx") Constructor. Format can be ltx or html, while document must be a Text::Amuse::Document object. # METHODS _lang document Accessor to the Text::Amuse::Document object (read-only, but you may call its method on that. fmt Accessor to the current format (read-only); is_html True if the format is html is_latex True if the format is latex process This method returns a array ref with the processed chunks. To get a sensible output you will have to join the pieces yourself. We don't return a joined string to avoid copying large amounts of data.  my$splat_pages = $obj->process(split => 1); foreach my$html (@$splat_pages) { # ...templating here... } If the format is html, the option split may be passed. Instead of a arrayref of chunks, an arrayref with html pages will be returned. Each page usually starts with an heading, and it's without <head> <body>. Footnotes are flushed and inserted at the end of each pages. E.g.  print @{$obj->process};

Return the formatted header as an hashref with key/value pairs.

## Internal Methods

add_footnote($element) Add the footnote to the internal list of found footnotes. flush_footnotes Return the list of primary footnotes found as a list of elements. flush_secondary_footnotes Return the list of secondary footnotes found as a list of elements. manage_html_footnote blkstring manage_regular($element_or_string, %options)

Main routine to transform a string to the given format

Options:

If set to true, do not parse the links and consider them plain strings

anchors

If set to true, parse the anchors and return two elements, the first is the processed string, the second is the processed anchors string.

inline_elements($string) Parse the provided string into a list of Text::Amuse::InlineElement objects. safe($string)

Be sure that the strings passed are properly escaped for the current format, to avoid command injection.

manage_paragraph

When we catch an header, we save it in the Output object, so we can emit the ToC. Level 5 is excluded as per doc.

It returns the numerical index (so you can inject the id).

reset_toc_stack

Clear out the list. This is called at the beginning of the main loop, so we don't collect duplicates over multiple runs.

table_of_contents

Emit the formatted ToC (if any). Please note that this method works even for the LaTeX format, even if does not produce usable output.

This because we can test if we need to emit a table of contents looking at this without searching the whole output.

The output is a list of hashref, where each hashref has the following keys:

level

The level of the header. Currently we store only levels 1-4, defining part(1), chapter(2), section(3) and subsection(4). Any other value means something is off (a.k.a., you found a bug).

index

The index of the entry, starting from 1.

string

The output.

The hashrefs are returned as copies, so they are safe to manipulate.

manage_verse
manage_comment
manage_inline_comment
manage_table
manage_table_html
manage_table_ltx
_split_table_in_hash
manage_example
manage_hr

Put an horizontal rule

manage_newpage

If it's LaTeX, insert a newpage

linkify($link) Here we see if it's a single one or a link/desc pair. Then dispatch _url_safe_escape # HELPERS Methods providing some fixed values blk_table image_re Regular expression to match image links. find_image($link)

Given the input string $link, return undef if it's not an image. If it is, return a Text::Amuse::Output::Image object. url_re html_table_mapping format_anchors($element)

Return a formatted string with the anchors found in the element.