Top Description Inners Fields Constructors Methods
uk.ac.ed.ph.snuggletex.utilities

public final Class LaTeXIndenter

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .IOException, .Reader, .Writer, java.util.regex.Matcher, .Pattern

Simple utility class that does very basic indenting of LaTeX.

Note

This has not been properly tested yet so is to be assumed experimental for the time being...!

Author
David McKain
Version
$Revision$

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
LaTeXIndenter.ParsingState

Encapsulates the different states our parser can be in

Field Summary

Modifier and TypeField and Description
private static final String
private static final Pattern
private int
blankLineCount

Number of consecutive blank lines encountered

private boolean
compactingBlankLines

Whether to compact >1 blank lines up as a single blank line

public static final int
DEFAULT_INDENT_WIDTH

Default indent width

public static final int
DEFAULT_MAX_INDENT_LEVEL

Default maximum indent level

private static final String
private static final Pattern
private int
indentLevel

Current indent level

private int
indentWidth

Current indent width

private static final String
private int
maxIndentLevel

Current maximum indent level

private final Writer
outputWriter

Writer that we are outputting to

private LaTeXIndenter.ParsingState
parsingState

Current parsing state

private boolean
verbatimMode

Set when we are in verbatim mode

Constructor Summary

AccessConstructor and Description
public
LaTeXIndenter(final Writer outputWriter)

Creates a new indenter that will output to outputWriter.

Method Summary

Modifier and TypeMethod and Description
private void
createIndent(int level)

public int
public int
private void
handleLine(String line)

Handles a single line, which may or may not end in a newline character

private void
private void
public boolean
public void
public void
run(Reader inputReader)

Indents the TeX read from the given inputReader, sending the results to outputWriter.

public void
setCompactingBlankLines(boolean condenseBlankLines)

public void
setIndentWidth(int indentWidth)

public void
setMaxIndentLevel(int maxIndentLevel)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BEGINback to summary
private static final String BEGIN
BEGIN_PATTERNback to summary
private static final Pattern BEGIN_PATTERN
blankLineCountback to summary
private int blankLineCount

Number of consecutive blank lines encountered

compactingBlankLinesback to summary
private boolean compactingBlankLines

Whether to compact >1 blank lines up as a single blank line

DEFAULT_INDENT_WIDTHback to summary
public static final int DEFAULT_INDENT_WIDTH

Default indent width

DEFAULT_MAX_INDENT_LEVELback to summary
public static final int DEFAULT_MAX_INDENT_LEVEL

Default maximum indent level

ENDback to summary
private static final String END
END_PATTERNback to summary
private static final Pattern END_PATTERN
indentLevelback to summary
private int indentLevel

Current indent level

indentWidthback to summary
private int indentWidth

Current indent width

LINE_SEPARATORback to summary
private static final String LINE_SEPARATOR
maxIndentLevelback to summary
private int maxIndentLevel

Current maximum indent level

outputWriterback to summary
private final Writer outputWriter

Writer that we are outputting to

parsingStateback to summary
private LaTeXIndenter.ParsingState parsingState

Current parsing state

verbatimModeback to summary
private boolean verbatimMode

Set when we are in verbatim mode

Constructor Detail

LaTeXIndenterback to summary
public LaTeXIndenter(final Writer outputWriter)

Creates a new indenter that will output to outputWriter. This will have default properties set and will compact blank lines by default.

Method Detail

createIndentback to summary
private void createIndent(int level) throws IOException
getIndentWidthback to summary
public int getIndentWidth()
getMaxIndentLevelback to summary
public int getMaxIndentLevel()
handleLineback to summary
private void handleLine(String line) throws IOException

Handles a single line, which may or may not end in a newline character

handleLineFragmentInDefaultStateback to summary
private void handleLineFragmentInDefaultState(String line) throws IOException
handleLineInDefaultStateback to summary
private void handleLineInDefaultState(String line) throws IOException
isCompactingBlankLinesback to summary
public boolean isCompactingBlankLines()
resetback to summary
public void reset()
runback to summary
public void run(Reader inputReader) throws IOException

Indents the TeX read from the given inputReader, sending the results to outputWriter. The inputReader will be closed afterwards; the outputWriter is left open so the caller should arrange to flush or close it as required.

setCompactingBlankLinesback to summary
public void setCompactingBlankLines(boolean condenseBlankLines)
setIndentWidthback to summary
public void setIndentWidth(int indentWidth)
setMaxIndentLevelback to summary
public void setMaxIndentLevel(int maxIndentLevel)
uk.ac.ed.ph.snuggletex.utilities back to summary

private final Enum LaTeXIndenter.ParsingState

extends Enum<LaTeXIndenter.ParsingState>
Class Inheritance

Encapsulates the different states our parser can be in

Field Summary

Modifier and TypeField and Description
public static final LaTeXIndenter.ParsingState
BEGIN_DECLARATION

Waiting to resolve a \\begin that started on the previous line

public static final LaTeXIndenter.ParsingState
DEFAULT

Normal TeX

public static final LaTeXIndenter.ParsingState
EMPTY_LINES

Handling a run of empty lines

public static final LaTeXIndenter.ParsingState
END_DECLARATION

Waiting to resolve a \\end that started on the previous line

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static LaTeXIndenter.ParsingState
public static LaTeXIndenter.ParsingState[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BEGIN_DECLARATIONback to summary
public static final LaTeXIndenter.ParsingState BEGIN_DECLARATION

Waiting to resolve a \\begin that started on the previous line

DEFAULTback to summary
public static final LaTeXIndenter.ParsingState DEFAULT

Normal TeX

EMPTY_LINESback to summary
public static final LaTeXIndenter.ParsingState EMPTY_LINES

Handling a run of empty lines

END_DECLARATIONback to summary
public static final LaTeXIndenter.ParsingState END_DECLARATION

Waiting to resolve a \\end that started on the previous line

Constructor Detail

ParsingStateback to summary
private ParsingState()

Method Detail

valueOfback to summary
public static LaTeXIndenter.ParsingState valueOf(String name)
valuesback to summary
public static LaTeXIndenter.ParsingState[] values()