Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.7 #169

Merged
merged 43 commits into from
Jul 13, 2019
Merged

Version 3.7 #169

merged 43 commits into from
Jul 13, 2019

Conversation

cmhughes
Copy link
Owner

This pull request implements the following:

  1. new feature new double-back-slash and comma poly-switches: polyswitch for double backslash #106
  2. new feature fine tuning: fineTuning #113
  3. new feature new poly-switch value for blank lines: Add blank line before every section marker? #146
  4. update better file extension handling: file extension upgrade #154
  5. new feature replacement mode switches: replacement mode switch: replace strings/regex using #155

This also resolves #148, #160, #166 and a bug reported at #167.

New features

  1. summary of new poly-switches

From #106, we have new the following new poly-switches

DBSStartsOnOwnLine:
DBSFinishesWithLineBreak
CommaStartsOnOwnLine
CommaFinishesWithLineBreak

I was particularly happy to be able to employ the Else object for each of these, because of which the overhead was manageable.

double back slash poly-switch

For example, starting with

\begin{pmatrix}
1 & 2 \\[2pt] 3 & 4 \\ [ 3 ex] 5&6\\[
\end{pmatrix}

and the YAML:

modifyLineBreaks:
environments:
DBSFinishesWithLineBreak: 1

and running

latexindent.pl -m pmatrix3.tex -l DBS3.yaml

gives

\begin{pmatrix}
1 & 2 \\[2pt]
3 & 4 \\ [ 3 ex]
5 & 6 \\[
4 pt
7 & 8
\end{pmatrix}

The example above is part of the documentation.

comma poly-switch

Starting with

\mycommand{ 1, 2, 3, 4, 5}[6, 7, 8, 9]

and running

latexindent.pl -m mycommand.tex -y="modifyLineBreaks:optionalArguments:CommaFinishesWithLineBreak:1,modifyLineBreaks:mandatoryArguments:CommaFinishesWithLineBreak:1"

gives

\mycommand{ 1,
	2,
	3,
	4,
	5}[6,
	7,
	8,
	9]
  1. fine tuning

From #113 we have:

# fineTuning allows you to tweak the internal pattern matching that 
# is central to latexindent.pl
fineTuning:
    environments:
      name: '[a-zA-Z@\*0-9_\\]+' 
    ifElseFi:
      name: '@?if[a-zA-Z@]*?' 
    commands:
      name: '[+a-zA-Z@\*0-9_\:]+?'
    keyEqualsValuesBracesBrackets:
      name: '[a-zA-Z@\*0-9_\/.\h\{\}:\#-]+?'
      follow: '(?:(?<!\\)\{)|,|(?:(?<!\\)\[)'
    NamedGroupingBracesBrackets:
      name: '[0-9\.a-zA-Z@\*><]+?'
      follow: '\h|\R|\{|\[|\$|\)|\('
    UnNamedGroupingBracesBrackets: 
      follow: '\{|\[|,|&|\)|\(|\$'
    arguments:
      before: '(?:#\d\h*;?,?\/?)+|\<.*?\>'
      between: '_|\^|\*'
    modifyLineBreaks:
      betterFullStop: '(?:\.\)(?!\h*[a-z]))|(?:(?<!(?:(?:e\.g)|(?:i\.e)|(?:etc))))\.(?!(?:[a-z]|[A-Z]|\-|~|\,|[0-9]))'
      doubleBackSlash: '\\\\(?:\h*\[\h*\d+\h*[a-zA-Z]+\h*\])?'
      comma: ','
  1. blank-line poly-switch

If you start with

section1.tex

\section{Introduction}
A sentence

and the YAML:

tmp.yaml

modifyLineBreaks:
    mandatoryArguments:
        RCuBFinishesWithLineBreak: 4

and run

latexindent.pl -m  section1.tex -l=tmp.yaml

then you receive

\section{Introduction}

A sentence

From #146 we have a new poly-swtich value

  1. file extension

latexindent.pl can now be called on any file, regardless of if the extesion is within fileExtensionPrefrerences. If no extension is given, then fileExtensionPreferences must still be consulted.

  1. replacement switches

Starting with the .tex file:

JHenneberg.tex

\begin{equation}
  \ell
  _{j}(x):= \prod
  _{0 \leq m \leq k; \quad m \neq j}\frac{x - x_m}{x_j - x_m}= \frac
  {x - x_0}{x_j - x_0}\cdots \frac
  {x -
    x_{j - 1}}{x_j -
    x_{j - 1}}\frac
  {x -
    x_{j + 1}}{x_j -
    x_{j + 1}}\cdots \frac
  {x - x_k}{x_j - x_k}
\end{equation}

\begin{equation}
  W =
  \begin{bmatrix}
    1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & z_i   & 0 & 1 & 0 & 0         \\ -z_i    & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1
  \end{bmatrix}
\end{equation}

\begin{itemize*}
  \item dünne Platten, kleine Verformungen \item dünne Platten, große Verformungen \item dicke Platten
\end{itemize*}

and the following YAML

JH.yaml

indentAfterItems:
    itemize*: 1

modifyLineBreaks:
    environments:
        DBSFinishesWithLineBreak: 1
    items:
        ItemStartsOnOwnLine: 1
    removeParagraphLineBreaks:
        environments: 
            equation: 1

replacements:
  -
    substitution: s/\h*\R\h*_/_/sg
    when: after
  -
    substitution: s/\h*_/_/sg
    when: after
  -
    substitution: s/([a-zA-Z:\}])\h*(=|-)\h*/$1 $2 /sg
    when: after

and running

latexindent.pl -m  -r JHenneberg.tex -l=JH.yaml

gives the following

output

\begin{equation}
	\ell_{j}(x): = \prod_{0 \leq m \leq k; \quad m \neq j}\frac{x - x_m}{x_j - x_m} = \frac {x - x_0}{x_j - x_0}\cdots \frac {x - x_{j - 1}}{x_j - x_{j - 1}}\frac {x - x_{j + 1}}{x_j - x_{j + 1}}\cdots \frac {x - x_k}{x_j - x_k}
\end{equation}

\begin{equation}
	W = 
	\begin{bmatrix}
		1    & 0   & 0 & 0 & 0 & 0 \\
		0    & 1   & 0 & 0 & 0 & 0 \\
		0    & 0   & 1 & 0 & 0 & 0 \\
		0    & z_i & 0 & 1 & 0 & 0 \\
		-z_i & 0   & 0 & 0 & 1 & 0 \\
		0    & 0   & 0 & 0 & 0 & 1
	\end{bmatrix}
\end{equation}

\begin{itemize*}
	\item dünne Platten, kleine Verformungen
	\item dünne Platten, große Verformungen
	\item dicke Platten
\end{itemize*}

…ess of if the extesion is within fileExtensionPrefrerences. If no extension is given, then fileExtensionPreferences must still be consulted
…itches, as detailed in #106. Next step: test and allow customisation of regex surrounding the double back slash
…ets with vertical space. Next step: comma poly-switch for optional and mandatory arguments
…erbatim blocks be included/excluded from the -r/-rr switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LSqBstartsOnOwnLine: -1 does not work?
1 participant