latex

package module
v0.0.0-...-dc387d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2017 License: MIT Imports: 5 Imported by: 0

README

Blackfriday-LaTeX

Blackfriday-LaTeX is a LaTeX renderer for the Blackfriday Markdown processor (v2).

Warning: Both Blackfriday v2 and this renderer are a work-in-progress.

Supported features

Among others:

  • Optional preamble
  • Title page
  • Table of contents
  • Footnotes
  • Tables
  • Fenced source code

Math support

Since Markdown and CommonMark do not make any provision for parsing math, the renderer uses the following rules to render math:

  • Math blocks are introduced with code blocks having the math language specifier.

      ``` math
      x+y=z
      ```
    
  • Inline math is introduce with inline code prefixed by $$ (space matters).

      `$$ x+y=z`
    

Documentation

See godoc.org.

Documentation

Overview

Package latex is a LaTeX renderer for the Blackfriday Markdown processor.

Example
package main

import (
	"fmt"

	bflatex "github.com/ambrevar/blackfriday-latex"

	bf "gopkg.in/russross/blackfriday.v2"
)

func main() {
	const input = `
# Section

Some _Markdown_ text.

## Subsection

Foobar.
`

	extensions := bf.CommonExtensions | bf.Titleblock
	renderer := &bflatex.Renderer{
		Author:    "John Doe",
		Languages: "english,french",
		Flags:     bflatex.TOC,
	}
	md := bf.New(bf.WithRenderer(renderer), bf.WithExtensions(extensions))

	ast := md.Parse([]byte(input))
	fmt.Printf("%s\n", renderer.Render(ast))
}
Output:

\section{Section}
Some \emph{Markdown} text.

\subsection{Subsection}
Foobar.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(input []byte, opts ...bf.Option) []byte

Run prints out the whole document with CompletePage and TOC flags enabled.

Types

type Flag

type Flag int

Flag controls the options of the renderer.

const (
	FlagsNone Flag = 0

	// CompletePage generates a complete LaTeX document, preamble included.
	CompletePage Flag = 1 << iota

	// ChapterTitle uses the titleblock (if the extension is on) as chapter title.
	// Ignored when CompletePage is on.
	ChapterTitle

	// No paragraph indentation.
	NoParIndent

	SkipLinks // Never link.
	Safelink  // Only link to trusted protocols.

	TOC // Generate the table of content.
)

type Renderer

type Renderer struct {

	// Flags allow customizing this renderer's behavior.
	Flags Flag

	// The document author displayed by the `\maketitle` command.
	// This will only display if the `Titleblock` extension is on and a title is
	// present.
	Author string

	// The languages to be used by the `babel` package.
	// Languages must be comma-spearated.
	Languages string
	// contains filtered or unexported fields
}

Renderer is a type that implements the Renderer interface for LaTeX output.

func (*Renderer) Render

func (r *Renderer) Render(ast *bf.Node) []byte

Render prints out the whole document from the ast, header and footer included.

func (*Renderer) RenderFooter

func (r *Renderer) RenderFooter(w io.Writer, ast *bf.Node)

RenderHeader prints the '\end{document}' if CompletePage is on.

func (*Renderer) RenderHeader

func (r *Renderer) RenderHeader(w io.Writer, ast *bf.Node)

RenderHeader prints the LaTeX preamble if CompletePage is on.

func (*Renderer) RenderNode

func (r *Renderer) RenderNode(w io.Writer, node *bf.Node, entering bool) bf.WalkStatus

RenderNode renders a single node. As a rule of thumb to enforce consistency, each node is responsible for appending the needed line breaks. Line breaks are never prepended.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL