Skip to content

Commit

Permalink
[latex] Make more configurable the fragment that generates the TeX st…
Browse files Browse the repository at this point in the history
…yles.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 1, 2015
1 parent ff784d0 commit 99b1c1c
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 11 deletions.
3 changes: 2 additions & 1 deletion latex/sarl-beamer-listing.sty
Expand Up @@ -2,7 +2,7 @@
\ProvidesPackage{sarl-beamer-listing}[2015/12/01]
\RequirePackage{algpseudocode}
\RequirePackage{listings}
\RequirePackage{relsize}
\RequirePackage{xspace}
\RequirePackage{xcolor}
\definecolor{SARLblue}{RGB}{43,88,121}
\definecolor{SARLlightblue}{RGB}{0,123,191}
Expand Down Expand Up @@ -48,4 +48,5 @@
frameround=fttt, % If framed, use this rounded corner style
}
\newcommand{\code}[1]{{\lstinline[basicstyle=\usebeamertemplate{code inline style}]{#1}}}
\newcommand{\sarl}{\mbox{SARL}\xspace}
\endinput
2 changes: 2 additions & 0 deletions latex/sarl-colorized-listing.sty
Expand Up @@ -2,6 +2,7 @@
\ProvidesPackage{sarl-colorized-listing}[2015/12/01]
\RequirePackage{algpseudocode}
\RequirePackage{listings}
\RequirePackage{xspace}
\RequirePackage{relsize}
\RequirePackage{xcolor}
\definecolor{SARLblue}{RGB}{43,88,121}
Expand Down Expand Up @@ -48,4 +49,5 @@
frameround=fttt, % If framed, use this rounded corner style
}
\newcommand{\code}[1]{{\lstinline[basicstyle=\normalcolor]{#1}}}
\newcommand{\sarl}{\mbox{SARL}\xspace}
\endinput
2 changes: 2 additions & 0 deletions latex/sarl-listing.sty
Expand Up @@ -2,6 +2,7 @@
\ProvidesPackage{sarl-listing}[2015/12/01]
\RequirePackage{algpseudocode}
\RequirePackage{listings}
\RequirePackage{xspace}
\RequirePackage{relsize}
\lstdefinelanguage{SARL}{%
morecomment=[s]{/*}{*/},
Expand Down Expand Up @@ -35,4 +36,5 @@
frameround=fttt, % If framed, use this rounded corner style
}
\newcommand{\code}[1]{{\lstinline[basicstyle=\normalcolor]{#1}}}
\newcommand{\sarl}{\mbox{SARL}\xspace}
\endinput
Expand Up @@ -37,6 +37,7 @@ public class LaTeXBeamerGenerator extends LaTeXListingsGenerator {
/** Constructs a generator for LaTeX Beamer.
*/
public LaTeXBeamerGenerator() {
clearRequirements();
setFloatBasicStyle("\\usebeamertemplate{code basic style}"); //$NON-NLS-1$
setInlineBasicStyle("\\usebeamertemplate{code inline style}"); //$NON-NLS-1$
setIdentifierStyle("\\usebeamertemplate{code identifier style}"); //$NON-NLS-1$
Expand Down
Expand Up @@ -27,6 +27,8 @@
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -99,6 +101,12 @@ public class LaTeXListingsGenerator extends ExternalLanguageSpecificationGenerat
public static final String DEFAULT_COLORIZED_KEYWORD_STYLE = "\\color{SARLkeyword}" //$NON-NLS-1$
+ DEFAULT_KEYWORD_STYLE;

/** Default definition for the overridable TeX requirements.
*/
public static final String[] DEFAULT_REQUIREMENTS = new String[] {
"relsize", //$NON-NLS-1$
};

private String outputName;

private String floatBasicStyle;
Expand All @@ -114,6 +122,16 @@ public class LaTeXListingsGenerator extends ExternalLanguageSpecificationGenerat
private String inlineBasicStyle;

private boolean useColors = true;

private boolean showLines = true;

private int lineStep = 2;

private int tabSize = 2;

private boolean showSpecialCharacters = false;

private Collection<String> requirements;

/** Construct the LaTeX generator.
*/
Expand Down Expand Up @@ -183,6 +201,61 @@ public void setUseColors(boolean useColors) {
this.useColors = useColors;
}

/** Set if the TeX style shows the line numbers.
*
* @param showLineNumbers <code>true</code> for showing the line numbers.
*/
public void setLineNumbers(boolean showLineNumbers) {
this.showLines = showLineNumbers;
}

/** Set the step between two line numbers.
*
* @param step the step between two line numbers.
*/
public void setLineStep(int step) {
this.lineStep = step;
}

/** Set the size of the tabs.
*
* @param size the size of one tab character.
*/
public void setTabSize(int size) {
this.tabSize = size;
}

/** Set if the TeX style shows the special characters (including spaces).
*
* @param showSpecialChars <code>true</code> for showing the special characters.
*/
public void setShowSpecialChars(boolean showSpecialChars) {
this.showSpecialCharacters = showSpecialChars;
}

/** Clear the list of the overridable requirements.
*/
public void clearRequirements() {
if (this.requirements == null) {
this.requirements = new ArrayList<>();
} else {
this.requirements.clear();
}
}

/** Add a TeX requirement.
*
* @param requirement the name of the TeX package.
*/
public void addRequirement(String requirement) {
if (!Strings.isEmpty(requirement)) {
if (this.requirements == null) {
this.requirements = new ArrayList<>();
}
this.requirements.add(requirement);
}
}

@Override
protected String getHumanReadableSpecificationName() {
return "LaTeX Listings style"; //$NON-NLS-1$
Expand Down Expand Up @@ -232,7 +305,14 @@ protected void generate(Set<String> literals, Set<String> keywords, Set<String>

append(sty, "\\RequirePackage'{'algpseudocode'}'"); //$NON-NLS-1$
append(sty, "\\RequirePackage'{'listings'}'"); //$NON-NLS-1$
append(sty, "\\RequirePackage'{'relsize'}'"); //$NON-NLS-1$
append(sty, "\\RequirePackage'{'xspace'}'"); //$NON-NLS-1$
Collection<String> requirements = this.requirements;
if (requirements == null) {
requirements = Arrays.asList(DEFAULT_REQUIREMENTS);
}
for (String requirement : requirements) {
append(sty, "\\RequirePackage'{'{0}'}'", requirement); //$NON-NLS-1$
}
if (this.useColors) {
append(sty, "\\RequirePackage'{'xcolor'}'"); //$NON-NLS-1$
}
Expand Down Expand Up @@ -309,15 +389,20 @@ protected void generate(Set<String> literals, Set<String> keywords, Set<String>

append(sty, " language={0}, % the default language of the code", langName); //$NON-NLS-1$

append(sty, " showspaces=false, % show spaces everywhere adding particular " //$NON-NLS-1$
+ "underscores; it overrides ''showstringspaces''"); //$NON-NLS-1$
append(sty, " showstringspaces=false, % underline spaces within strings only"); //$NON-NLS-1$
append(sty, " showtabs=false, % show tabs within strings adding particular underscores"); //$NON-NLS-1$
append(sty, " numbers=left,% Numbers on left"); //$NON-NLS-1$
append(sty, " firstnumber=1, % First line number"); //$NON-NLS-1$
append(sty, " numberfirstline=false, %Start numbers at first line"); //$NON-NLS-1$
append(sty, " stepnumber=2, % the step between two line-numbers. If it''s 1, each line will be numbered"); //$NON-NLS-1$
append(sty, " tabsize=2, % sets default tabsize to 2 spaces"); //$NON-NLS-1$
append(sty, " showspaces={0}, % show spaces everywhere adding particular " //$NON-NLS-1$
+ "underscores; it overrides ''showstringspaces''", this.showSpecialCharacters); //$NON-NLS-1$
append(sty, " showstringspaces={0}, % underline spaces within strings only", //$NON-NLS-1$
this.showSpecialCharacters);
append(sty, " showtabs={0}, % show tabs within strings adding particular underscores", //$NON-NLS-1$
this.showSpecialCharacters);
if (this.showLines) {
append(sty, " numbers=left,% Numbers on left"); //$NON-NLS-1$
append(sty, " firstnumber=1, % First line number"); //$NON-NLS-1$
append(sty, " numberfirstline=false, %Start numbers at first line"); //$NON-NLS-1$
append(sty, " stepnumber={0}, % the step between two line-numbers. " //$NON-NLS-1$
+ "If it''s 1, each line will be numbered", this.lineStep); //$NON-NLS-1$
}
append(sty, " tabsize={0}, % sets default tabsize to 2 spaces", this.tabSize); //$NON-NLS-1$
append(sty, " title=\\lstname, % show the filename of files included with " //$NON-NLS-1$
+ "\\lstinputlisting; also try caption instead of title"); //$NON-NLS-1$
append(sty, " frameround=fttt, % If framed, use this rounded corner style"); //$NON-NLS-1$
Expand All @@ -329,6 +414,7 @@ protected void generate(Set<String> literals, Set<String> keywords, Set<String>
}
inlineBasicStyle = Strings.emptyIfNull(inlineBasicStyle);
append(sty, "\\newcommand'{'\\code'}'[1]'{{'\\lstinline[basicstyle={0}]'{'#1'}}}'", inlineBasicStyle); //$NON-NLS-1$
append(sty, "\\newcommand'{'\\sarl'}{'\\mbox'{'SARL'}'\\xspace'}'"); //$NON-NLS-1$

append(sty, "\\endinput"); //$NON-NLS-1$

Expand Down

0 comments on commit 99b1c1c

Please sign in to comment.