Skip to content

Commit

Permalink
[contribs] Add '[no]sarlcolors' option to the LaTeX styles.
Browse files Browse the repository at this point in the history
close #680

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed May 30, 2017
1 parent d53bf3d commit 829eb7d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
11 changes: 10 additions & 1 deletion formatting-styles/latex/sarl-beamer-listing.sty
Expand Up @@ -22,7 +22,11 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-beamer-listing}[2017/04/04]
\ProvidesPackage{sarl-beamer-listing}[2017/05/30]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
\ProcessOptions*
\RequirePackage{algpseudocode}
\RequirePackage{listings}
\RequirePackage{xspace}
Expand Down Expand Up @@ -70,4 +74,9 @@
\newcommand{\code}[1]{\ifmmode\text{\lstinline[basicstyle=\usebeamertemplate{code inline style}]{#1}}\else\lstinline[basicstyle=\usebeamertemplate{code inline style}]{#1}\fi}
\newcommand{\sarl}{\mbox{SARL}\xspace}
\newcommand{\sarlversion}{0.6}
\ifusesarlcolors
\setbeamercolor*{code keyword}{fg=SARLkeyword}
\setbeamercolor*{code string}{fg=SARLstring}
\setbeamercolor*{code comment}{fg=SARLcomment}
\fi
\endinput
6 changes: 5 additions & 1 deletion formatting-styles/latex/sarl-colorized-listing.sty
Expand Up @@ -22,7 +22,11 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-colorized-listing}[2017/04/04]
\ProvidesPackage{sarl-colorized-listing}[2017/05/30]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
\ProcessOptions*
\RequirePackage{algpseudocode}
\RequirePackage{listings}
\RequirePackage{xspace}
Expand Down
6 changes: 5 additions & 1 deletion formatting-styles/latex/sarl-listing.sty
Expand Up @@ -22,7 +22,11 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-listing}[2017/04/04]
\ProvidesPackage{sarl-listing}[2017/05/30]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
\ProcessOptions*
\RequirePackage{algpseudocode}
\RequirePackage{listings}
\RequirePackage{xspace}
Expand Down
Expand Up @@ -26,6 +26,8 @@
import com.google.inject.Injector;
import org.eclipse.xtext.generator.IGeneratorFragment;

import io.sarl.lang.mwe2.externalspec.IStyleAppendable;

/**
* A {@link IGeneratorFragment} that create the language specification for
* the LaTeX Beamer.
Expand Down Expand Up @@ -55,6 +57,17 @@ public void initialize(Injector injector) {
setBasenameTemplate(BEAMER_BASENAME_PATTERN);
}

@Override
protected void generateExtension(IStyleAppendable it) {
it.append("\\ifusesarlcolors"); //$NON-NLS-1$
it.increaseIndentation().newLine();
it.appendNl("\\setbeamercolor*{code keyword}{fg=SARLkeyword}"); //$NON-NLS-1$
it.appendNl("\\setbeamercolor*{code string}{fg=SARLstring}"); //$NON-NLS-1$
it.append("\\setbeamercolor*{code comment}{fg=SARLcomment}"); //$NON-NLS-1$
it.decreaseIndentation().newLine();
it.appendNl("\\fi"); //$NON-NLS-1$
}

@Override
public String toString() {
return "LaTeX Beamer"; //$NON-NLS-1$
Expand Down
Expand Up @@ -281,6 +281,10 @@ protected void generate(IStyleAppendable it, Set<String> literals, Set<String> e
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); //$NON-NLS-1$
it.appendNl("\\ProvidesPackage'{'{0}'}'[{1}]", simpleBasename, dateFormat.format(new Date())); //$NON-NLS-1$

if (generateOptions(it)) {
it.appendNl("\\ProcessOptions*"); //$NON-NLS-1$
}

it.appendNl("\\RequirePackage{algpseudocode}"); //$NON-NLS-1$
it.appendNl("\\RequirePackage{listings}"); //$NON-NLS-1$
it.appendNl("\\RequirePackage{xspace}"); //$NON-NLS-1$
Expand Down Expand Up @@ -395,9 +399,34 @@ protected void generate(IStyleAppendable it, Set<String> literals, Set<String> e
it.appendNl("\\newcommand{\\sarl}{\\mbox{SARL}\\xspace}"); //$NON-NLS-1$
it.appendNl("\\newcommand'{'\\sarlversion'}{'{0}'}'", getLanguageVersion()); //$NON-NLS-1$

generateExtension(it);

it.appendNl("\\endinput"); //$NON-NLS-1$
}

/** Generate the package definition extensions.
*
* @param it the target.
* @since 0.6
*/
protected void generateExtension(IStyleAppendable it) {
//
}

/** Generate the optional extensions.
*
* @param it the target.
* @return {@code true} if options are generated.
* @since 0.6
*/
@SuppressWarnings("static-method")
protected boolean generateOptions(IStyleAppendable it) {
it.appendNl("\\newif\\ifusesarlcolors\\usesarlcolorstrue"); //$NON-NLS-1$
it.appendNl("\\DeclareOption{sarlcolors}{\\global\\usesarlcolorstrue}"); //$NON-NLS-1$
it.appendNl("\\DeclareOption{nosarlcolors}{\\global\\usesarlcolorsfalse}"); //$NON-NLS-1$
return true;
}

/** Appendable for tex-based styles.
*
* @author $Author: sgalland$
Expand Down

0 comments on commit 829eb7d

Please sign in to comment.