diff --git a/mlsshared.sty b/mlsshared.sty new file mode 100644 index 000000000..927c4f618 --- /dev/null +++ b/mlsshared.sty @@ -0,0 +1,172 @@ +% Package with preamble content to be shared by the main document and its figures. + +% Formatting for filenames, URIs, etc. +% For now, the content is wrapped in \mbox to avoid hyphenation to inject +% hyphens. A better solution could be to change the directory separator +% characters to also produce an \allowbreak{} following the directory separator. +\newcommand{\filename}[1]{\mbox{\textsf{#1}}} + +\usepackage{listings} +\usepackage{color} +\usepackage[table]{xcolor} + +\definecolor{keywordcolor1} {rgb}{0.00, 0.20, 0.47} +\definecolor{keywordcolor3} {rgb}{0.33, 0.24, 0.03} +\definecolor{commentcolor} {rgb}{0.07, 0.46, 0.00} + +% It would be nice to have comments set in normal variable-width font without any sort of +% column alignment by the listsings.sty package, just like the comments look in the LaTeXML build. +% Adding the following \commentfullflexible to the 'commentstyle' +% makes words look good, but the words are still aligned in mysterious ways. +%\let\commentfullflexible\lst@column@fullflexible + +% See https://github.com/modelica-tools/listings-modelica/blob/master/listings-modelica.cfg +% Note: Changed comment color from green to [rgb]{0,0.4,0} - since the other variant was too distracting +% And added pure,impure,stream as keywords +% Remove cross as red +% Note: have basicstyle=\upshape\small\ttfamily in all languages, +% except the dialect [short]modelica - which is used for inline listings. +% Apart from that change that dialect should be identical to modelica + +% The red keyword part is a bit unclear. +% The current logic is that "operators" are marked specially, but not normal functions. +% +% Note that Integer is both a predefined type and a function; we cannot treat them differently. +% Another solution would be to remove this completely. +\lstdefinelanguage{modelica}{% Language for use with the lstlisting environment. + basicstyle=\upshape\smallifpdf\ttfamily, % Font size for displayed code listings. + alsoletter={}, +% otherkeywords={-, =, +, [, ], (, ), \{, \}, :, *, !},% + morekeywords=[1]{}, % blue Keywords + morekeywords=[2]{% blue + bold keywords + annotation,assert,block,break,class,connector,constant,constrainedby,discrete,% + each,encapsulated,enumeration,else,elseif,elsewhen,end,exit,expandable,extends,external,final,flow,for,% + function,if,in,inner,initial,input,import,loop,model,nondiscrete,operator,outer,% + output,package,parameter,partial,record,redeclare,replaceable,return,% + size,stream,terminate,then,type,when,while,within,algorithm,equation,% + protected,public,and,false,not,or,true,pure,impure,transition,initialState},% + % Note: initial is in both variants - depending on context, use first variant + morekeywords=[3]{% red keywords - only special functions and classes: 3.7.2 #derivative-and-special-purpose-operators-with-function-syntax + % 3.7.3 #event-related-operators-with-function-syntax (except initial) and 4.8 #predefined-types-and-classes + connect,der,delay,cardinality,homotopy,semiLinear,inStream,actualStream,spatialDistribution,getInstanceName,% + terminal,noEvent,smooth,sample,pre,edge,change,reinit,% + previous,hold,subSample,superSample,shiftSample,backSample,noClock,firstTick,interval,% + Real,Integer,Boolean,String},% + comment=[l]{//}, % comment lines + morecomment=[s]{/*}{*/}, % comment blocs + morestring=[b]{'}, + morestring=[b]{"}, +}[keywords,comments,strings] + +\lstdefinelanguage[short]{modelica}[]{modelica}{% Language for use with the \lstinline command. + basicstyle=\upshape\ttfamily, % Font size for inline code snippets. +} + +% Special dialect of Modelica to use when there are URLs appearing outside string literals, to avoid the part +% starting with '//' being treated as comment. +\lstdefinelanguage[nocomment]{modelica}[short]{modelica}{% + commentstyle=\upshape\ttfamily, % Camouflage comments as workaround for not being able to remove rest-of-line comment recognition. +} + +% Note: within only a keyword in grammar +\lstdefinelanguage{grammar}{% + basicstyle=\upshape\smallifpdf\ttfamily, % size of fonts used for the code + alsoletter={}, + alsodigit={-}, + breaklines=true, + breakatwhitespace=true, + morekeywords=[2]{% + letters,annotation,assert,block,break,class,connector,constant,constrainedby,discrete,% + each,encapsulated,else,elseif,elsewhen,end,exit,expandable,extends,external,final,flow,for,% + function,if,in,inner,initial,input,import,loop,model,nondiscrete,operator,outer,% + output,package,parameter,partial,record,redeclare,replaceable,return,% + size,stream,terminate,then,type,when,while,algorithm,equation,% + protected,public,and,false,not,or,true,pure,impure,stream,transition,initialState,% + within}, + morekeywords=[1]{|} +}[keywords,comments,strings] + +% Duplicate this definition here to avoid issue - and name it "fortran77" to avoid problem in LatexML +\lstdefinelanguage{fortran77}{% + basicstyle=\upshape\smallifpdf\ttfamily, % size of fonts used for the code + morekeywords={% + ASSIGN,BACKSPACE,CALL,CHARACTER,% + CLOSE,COMMON,COMPLEX,CONTINUE,DATA,DIMENSION,DO,DOUBLE,% + ELSE,ELSEIF,END,ENDIF,ENDDO,ENTRY,EQUIVALENCE,EXTERNAL,% + FILE,FORMAT,FUNCTION,GO,TO,GOTO,IF,IMPLICIT,% + INQUIRE,INTEGER,INTRINSIC,LOGICAL,% + OPEN,PARAMETER,PAUSE,PRECISION,PRINT,PROGRAM,READ,REAL,% + RETURN,REWIND,STOP,SUBROUTINE,THEN,% + WRITE,SAVE}, + morekeywords=[2]{% + ACCESS,BLANK,BLOCK,DIRECT,EOF,ERR,EXIST,% + FMT,FORM,FORMATTED,IOSTAT,NAMED,NEXTREC,NUMBER,OPENED,% + REC,RECL,SEQUENTIAL,STATUS,TYPE,UNFORMATTED,UNIT}, + morekeywords=[3]{% + INT,DBLE,CMPLX,ICHAR,CHAR,AINT,ANINT,% left out real + NINT,ABS,MOD,SIGN,DIM,DPROD,MAX,MIN,AIMAG,CONJG,SQRT,EXP,LOG,% + LOG10,SIN,COS,TAN,ASIN,ACOS,ATAN,ATAN2,SINH,COSH,TANH,LGE,LLE,LLT,% + LEN,INDEX}, + morekeywords=[4]{AND,EQ,EQV,FALSE,GE,GT,OR,LE,LT,NE,NEQV,NOT,TRUE},% + sensitive=f, % not Fortran-77 standard, but allowed in Fortran-95 %% + morecomment=[f]*, + morecomment=[f]C, + morecomment=[f]c, + morestring=[d]", % not Fortran-77 standard, but allowed in Fortran-95 %% + morestring=[d]' +}[keywords,comments,strings] + +\lstdefinelanguage{C}{% + basicstyle=\upshape\smallifpdf\ttfamily, % size of fonts used for the code + morekeywords={% + auto,break,case,char,const,continue,default,do,double,% + else,enum,extern,float,for,goto,if,int,long,register,return,% + short,signed,sizeof,static,struct,switch,typedef,union,unsigned,% + void,volatile,while}, + % henrikt-ma: How about adding some highlighting of 'size_t' as a recognized name? + sensitive, + morecomment=[s]{/*}{*/}, + morecomment=[l]//, % nonstandard + morestring=[b]", + morestring=[b]', + moredelim=*[directive]\#, + moredirectives={% + define,elif,else,endif,error,if,ifdef,ifndef,line,% + include,pragma,undef,warning} +}[keywords,comments,strings,directives] + +% Note: \lstinline!...! used for inline Modelica using [short]modelica + +\lstset{% + backgroundcolor=\color{white}, % choose the background color + mathescape=true, + breaklines=true, % automatic line breaking only at white-space + keepspaces, % don't remove space such as those after closing parenthesis + captionpos=b, % sets the caption-position to bottom + commentstyle=\color{commentcolor}\sffamily, % comment style + keywordstyle=\color{red}, % Unused keyword style in bright red to make it easy to detect and fix. + keywordstyle=[1]\color{keywordcolor1}, + keywordstyle=[2]\color{keywordcolor1}\bfseries, + keywordstyle=[3]\color{keywordcolor3}, + stringstyle=\color{black}, % string literal style + language=[short]modelica, % Language that will be used by default, in particluar by plain \lstinline. + showstringspaces=false, + frame=lrtb, + belowskip=0pt, +} + +% Misc math +\newcommand{\ud}{\mathrm{d}} +\newcommand{\pdfrac}[3][\@nil]{% + \def\tmp{#1}% + \ifx\tmp\@nnil + \frac{\ud#2}{\ud#3}% + \else + \frac{\ud^{#1}#2}{\ud#3^{#1}}% + \fi% +} +\newcommand{\abs}[1]{\left\lvert #1{} \right\rvert} + +% Text mode additions +\newcommand{\textgreatereq}{$\geq$} +\newcommand{\textlesseq}{$\leq$} diff --git a/preamble.tex b/preamble.tex index 6c71d30e7..3ba4d9d20 100644 --- a/preamble.tex +++ b/preamble.tex @@ -14,7 +14,6 @@ % For non-floating figures: \usepackage{float} - % Prefer pdf for pdf % https://tex.stackexchange.com/questions/1072/which-graphics-formats-can-be-included-in-documents-processed-by-latex-or-pdflat \usepackage{ifpdf} @@ -83,10 +82,25 @@ % The default (magenta for urls and red for internal links) isn't nice \hypersetup{bookmarksnumbered=true, hidelinks, urlcolor=blue, linkcolor=blue} \usepackage{multirow} % for multirow entries in tables -\usepackage{listings} -%\usepackage{enumitem} % Package not available for continuous integration builds. -\usepackage{color} -\usepackage[table]{xcolor} + +% When producing PDF, the ttfamily looks better in size \small, but with LaTeXML this becomes too small, +% and the size is applied deep down on the HTML elements, making it hard to adjust using CSS. +% Thus, the problem has to be addressed already when a listings language's 'basicstyle' is defined. +% This needs to go before mlsshared.sty is loaded. +\ifpdf +\let\smallifpdf\small +\else +\let\smallifpdf\normalsize +\fi + +\usepackage{mlsshared} + +% Settings in addition to those in mlsshared.sty. +\lstset{% + xleftmargin=\fboxsep, + xrightmargin=-\fboxsep, +} + \def\S0#1#2{\hypertarget{#2}\chapter{#1}\label{#2}} \def\S1#1#2{\hypertarget{#2}\section{#1}\label{#2}} \def\S2#1#2{\hypertarget{#2}\subsection{#1}\label{#2}} @@ -96,6 +110,7 @@ % Simple numbering of lists, should preferably use \usepackage{enumitem} % https://stackoverflow.com/questions/2007627/latex-how-can-i-create-nested-lists-which-look-this-1-1-1-1-1-1-1-2-1-2 +%\usepackage{enumitem} % Package not available for continuous integration builds. \renewcommand{\labelenumi}{\arabic{enumi}.} \renewcommand{\labelenumii}{\labelenumi\arabic{enumii}.} \renewcommand{\labelenumiii}{\labelenumii\arabic{enumiii}.} @@ -133,12 +148,6 @@ % to an index/glossary. \newcommand{\firstuse}[1]{\emph{#1}} -% Formatting for filenames, URIs, etc. -% For now, the content is wrapped in \mbox to avoid hyphenation to inject -% hyphens. A better solution could be to change the directory separator -% characters to also produce an \allowbreak{} following the directory separator. -\newcommand{\filename}[1]{\mbox{\textsf{#1}}} - % Formatting of table headings. \newcommand{\tablehead}[1]{\textit{#1}} @@ -173,163 +182,6 @@ \setcounter{secnumdepth}{5} % Note: Toc changed for appendex \setcounter{tocdepth}{1} -\definecolor{keywordcolor1} {rgb}{0.00, 0.20, 0.47} -\definecolor{keywordcolor3} {rgb}{0.33, 0.24, 0.03} % Red color used in the past: {0.90, 0.00, 0.00} -\definecolor{commentcolor} {rgb}{0.07, 0.46, 0.00} - -% When producing PDF, the ttfamily looks better in size \small, but with LaTeXML this becomes too small, -% and the size is applied deep down on the HTML elements, making it hard to adjust using CSS. -% Thus, the problem has to be addressed already when a listings language's 'basicstyle' is defined. -\ifpdf -\let\smallifpdf\small -\else -\let\smallifpdf\normalsize -\fi - -% It would be nice to have comments set in normal variable-width font without any sort of -% column alignment by the listsings.sty package, just like the comments look in the LaTeXML build. -% Adding the following \commentfullflexible to the 'commentstyle' -% makes words look good, but the words are still aligned in mysterious ways. -%\makeatletter -%\let\commentfullflexible\lst@column@fullflexible -%\makeatother - -% See https://github.com/modelica-tools/listings-modelica/blob/master/listings-modelica.cfg -% Note: Changed comment color from green to [rgb]{0,0.4,0} - since the other variant was too distracting -% And added pure,impure,stream as keywords -% Remove cross as red -% Note: have basicstyle=\upshape\small\ttfamily in all languages, -% except the dialect [short]modelica - which is used for inline listings. -% Apart from that change that dialect should be identical to modelica - -% The red keyword part is a bit unclear. -% The current logic is that "operators" are marked specially, but not normal functions. -% -% Note that Integer is both a predefined type and a function; we cannot treat them differently. -% Another solution would be to remove this completely. -\lstdefinelanguage{modelica}{% Language for use with the lstlisting environment. - basicstyle=\upshape\smallifpdf\ttfamily, % Font size for displayed code listings. - alsoletter={}, -% otherkeywords={-, =, +, [, ], (, ), \{, \}, :, *, !},% - morekeywords=[1]{}, % blue Keywords - morekeywords=[2]{% blue + bold keywords - annotation,assert,block,break,class,connector,constant,constrainedby,discrete,% - each,encapsulated,enumeration,else,elseif,elsewhen,end,exit,expandable,extends,external,final,flow,for,% - function,if,in,inner,initial,input,import,loop,model,nondiscrete,operator,outer,% - output,package,parameter,partial,record,redeclare,replaceable,return,% - size,stream,terminate,then,type,when,while,within,algorithm,equation,% - protected,public,and,false,not,or,true,pure,impure,transition,initialState},% - % Note: initial is in both variants - depending on context, use first variant - morekeywords=[3]{% red keywords - only special functions and classes: 3.7.2 #derivative-and-special-purpose-operators-with-function-syntax - % 3.7.3 #event-related-operators-with-function-syntax (except initial) and 4.8 #predefined-types-and-classes - connect,der,delay,cardinality,homotopy,semiLinear,inStream,actualStream,spatialDistribution,getInstanceName,% - terminal,noEvent,smooth,sample,pre,edge,change,reinit,% - previous,hold,subSample,superSample,shiftSample,backSample,noClock,firstTick,interval,% - Real,Integer,Boolean,String},% - comment=[l]{//}, % comment lines - morecomment=[s]{/*}{*/}, % comment blocs - morestring=[b]{'}, - morestring=[b]{"}, -}[keywords,comments,strings] - -\lstdefinelanguage[short]{modelica}[]{modelica}{% Language for use with the \lstinline command. - basicstyle=\upshape\ttfamily, % Font size for inline code snippets. -} - -% Special dialect of Modelica to use when there are URLs appearing outside string literals, to avoid the part -% starting with '//' being treated as comment. -\lstdefinelanguage[nocomment]{modelica}[short]{modelica}{% - commentstyle=\upshape\ttfamily, % Camouflage comments as workaround for not being able to remove rest-of-line comment recognition. -} - -% Note: within only a keyword in grammar -\lstdefinelanguage{grammar}{% - basicstyle=\upshape\smallifpdf\ttfamily, % size of fonts used for the code - alsoletter={}, - alsodigit={-}, - breaklines=true, - breakatwhitespace=true, - morekeywords=[2]{% - letters,annotation,assert,block,break,class,connector,constant,constrainedby,discrete,% - each,encapsulated,else,elseif,elsewhen,end,exit,expandable,extends,external,final,flow,for,% - function,if,in,inner,initial,input,import,loop,model,nondiscrete,operator,outer,% - output,package,parameter,partial,record,redeclare,replaceable,return,% - size,stream,terminate,then,type,when,while,algorithm,equation,% - protected,public,and,false,not,or,true,pure,impure,stream,transition,initialState,% - within}, - morekeywords=[1]{|} -}[keywords,comments,strings] - -\lstset{% - backgroundcolor=\color{white}, % choose the background color - mathescape=true, - breaklines=true, % automatic line breaking only at white-space - keepspaces, % don't remove space such as those after closing parenthesis - captionpos=b, % sets the caption-position to bottom - commentstyle=\color{commentcolor}\sffamily, % comment style - keywordstyle=\color{red}, % Unused keyword style in bright red to make it easy to detect and fix. - keywordstyle=[1]\color{keywordcolor1}, - keywordstyle=[2]\color{keywordcolor1}\bfseries, - keywordstyle=[3]\color{keywordcolor3}, - stringstyle=\color{black}, % string literal style - language=[short]modelica, % Language that will be used by default, in particluar by plain \lstinline. - showstringspaces=false, - frame=lrtb, - xleftmargin=\fboxsep, - xrightmargin=-\fboxsep, - belowskip=0pt, -} - -% Duplicate this definition here to avoid issue - and name it "fortran77" to avoid problem in LatexML -\lstdefinelanguage{fortran77}{% - basicstyle=\upshape\smallifpdf\ttfamily, % size of fonts used for the code - morekeywords={% - ASSIGN,BACKSPACE,CALL,CHARACTER,% - CLOSE,COMMON,COMPLEX,CONTINUE,DATA,DIMENSION,DO,DOUBLE,% - ELSE,ELSEIF,END,ENDIF,ENDDO,ENTRY,EQUIVALENCE,EXTERNAL,% - FILE,FORMAT,FUNCTION,GO,TO,GOTO,IF,IMPLICIT,% - INQUIRE,INTEGER,INTRINSIC,LOGICAL,% - OPEN,PARAMETER,PAUSE,PRECISION,PRINT,PROGRAM,READ,REAL,% - RETURN,REWIND,STOP,SUBROUTINE,THEN,% - WRITE,SAVE}, - morekeywords=[2]{% - ACCESS,BLANK,BLOCK,DIRECT,EOF,ERR,EXIST,% - FMT,FORM,FORMATTED,IOSTAT,NAMED,NEXTREC,NUMBER,OPENED,% - REC,RECL,SEQUENTIAL,STATUS,TYPE,UNFORMATTED,UNIT}, - morekeywords=[3]{% - INT,DBLE,CMPLX,ICHAR,CHAR,AINT,ANINT,% left out real - NINT,ABS,MOD,SIGN,DIM,DPROD,MAX,MIN,AIMAG,CONJG,SQRT,EXP,LOG,% - LOG10,SIN,COS,TAN,ASIN,ACOS,ATAN,ATAN2,SINH,COSH,TANH,LGE,LLE,LLT,% - LEN,INDEX}, - morekeywords=[4]{AND,EQ,EQV,FALSE,GE,GT,OR,LE,LT,NE,NEQV,NOT,TRUE},% - sensitive=f, % not Fortran-77 standard, but allowed in Fortran-95 %% - morecomment=[f]*, - morecomment=[f]C, - morecomment=[f]c, - morestring=[d]", % not Fortran-77 standard, but allowed in Fortran-95 %% - morestring=[d]' -}[keywords,comments,strings] - -\lstdefinelanguage{C}{% - basicstyle=\upshape\smallifpdf\ttfamily, % size of fonts used for the code - morekeywords={% - auto,break,case,char,const,continue,default,do,double,% - else,enum,extern,float,for,goto,if,int,long,register,return,% - short,signed,sizeof,static,struct,switch,typedef,union,unsigned,% - void,volatile,while}, - % henrikt-ma: How about adding some highlighting of 'size_t' as a recognized name? - sensitive, - morecomment=[s]{/*}{*/}, - morecomment=[l]//, % nonstandard - morestring=[b]", - morestring=[b]', - moredelim=*[directive]\#, - moredirectives={% - define,elif,else,endif,error,if,ifdef,ifndef,line,% - include,pragma,undef,warning} -}[keywords,comments,strings,directives] - -% Note: \lstinline!...! used for inline Modelica using [short]modelica % Warning: The way of adding \label inside the theoremstyle below is currently working at LaTeXML version 0.8.4, % but was broken for a while on their master branch, see @@ -410,23 +262,6 @@ \endlist } -% Misc math -\makeatletter -\newcommand{\pdfrac}[3][\@nil]{% - \def\tmp{#1}% - \ifx\tmp\@nnil - \frac{\mathrm{d}#2}{\mathrm{d}#3}% - \else - \frac{\mathrm{d}^{#1}#2}{\mathrm{d}#3^{#1}}% - \fi% -} -\makeatother -\newcommand{\abs}[1]{\left\lvert #1{} \right\rvert} - -% Text mode additions -\newcommand{\textgreatereq}{$\geq$} -\newcommand{\textlesseq}{$\leq$} - % Change all \cref and \Cref variants below chapter to use "section" \crefname{subsection}{section}{sections} \Crefname{subsection}{Section}{Sections}