4

Suppose I have the following code listing:

font/lm/.code={
\RequirePackage{fix-cm}
\RequirePackage[rm={lining=true}]{cfr-lm}
\RequirePackage{amsfonts, amssymb}
% Define tabular-lining figures and oldstyle windows
\providerobustcmd{\tablining}{\tlstyle}
\providerobustcmd{\propold}{\postyle}
% Define bold small caps for AC and other header labels
\providerobustcmd{\labelstyle}[#1]{}
% Define title style
\providerobustcmd{}[]{}
\RequirePackage{inconsolata}
},

Running latexindent.pl on this file with the default options as specified in defaultSettings.yaml gives this result:

font/lm/.code={
        \RequirePackage{fix-cm}
        \RequirePackage[rm={lining=true}]{cfr-lm}
        \RequirePackage{amsfonts, amssymb}
        % Define tabular-lining figures and oldstyle windows
        \providerobustcmd{\tablining}{\tlstyle}
        \providerobustcmd{\propold}{\postyle}
        % Define bold small caps for AC and other header labels
        \providerobustcmd{\labelstyle}[#1]{}
        % Define title style
        \providerobustcmd{}[]{}
        \RequirePackage{inconsolata}
    },

Ideally, I'd like the indent of the closing brace } to be on the same level as the font/lm/... line, and the argument within the braces, i.e. the various \RequirePackages and the providerobustcmd{}... to be indented by four spaces, similar to the function bodies of C-style languages:

int main() {
    // code
}

Of course, I'd like to extend this to optional arguments as well—this would be particularly useful when typesetting tikzpicture/pgfplots environments, where there are easily tens of arguments within the square brackets.

SRSR333
  • 568

1 Answers1

1

After fiddling around with different permutations of the settings in defaultSettings.yaml, I arrived at the following code segment that works precisely as intended: braces not indented, body code indented as specified (intended-indented wordplay not intended).

# set noAdditionalIndent globally for codeblocks
noAdditionalIndentGlobal:
    environments: 0
    commands: 1
    optionalArguments: 0
    mandatoryArguments: 0
    ifElseFi: 0
    items: 0
    keyEqualsValuesBracesBrackets: 1
    namedGroupingBracesBrackets: 1
    UnNamedGroupingBracesBrackets: 1
    specialBeginEnd: 0
    afterHeading: 0
    filecontents: 0

To be very honest, I am not quite sure why this works, but it does. I shall consult the manual and post an update when I can.

SRSR333
  • 568
  • 1
    I'm glad you found the answer. For your example the necessary part of your YAML file is keyEqualsValuesBracesBrackets: 1. See https://latexindentpl.readthedocs.io/en/latest/sec-default-user-local.html#noadditionalindent-and-indentrules and also https://latexindentpl.readthedocs.io/en/latest/sec-default-user-local.html#keyequalsvaluesbracesbrackets for reference. – cmhughes Jul 19 '20 at 19:57
  • By the way, if the documentation can be clearer on this issue, please do feel free to raise an issue or submit a pull request to (the develop branch) https://github.com/cmhughes/latexindent.pl – cmhughes Jul 20 '20 at 08:40