Closed avatar-lavventura closed 2 years ago
Thanks for this, it was interesting!
Put the following in your yaml settings, say latexindent.yaml
commandCodeBlocks:
stringsAllowedBetweenArguments:
- 'in' # allows 'in' between arguments
- '\\[a-z]\/\\[a-z]' # allows any letter followed by / followed by another letter between arguments
noAdditionalIndent:
foreach:
body: 1
and then run
latexindent.pl -l myfile.tex
and you receive
\foreach \i/\j in {0.5/$H_{0}$, 1.5/$H_{0}$ } {
\node at (4.5, -\i) {\j};
}
\node[PR] at (3.48, -0.5) {};
\node[PR] at (3.48, -1.5) {};
\node[PR] at (3.48, -3.5) {};
\node[PR] at (3.48, -1.5) {};
in
and \i/\j
between arguments by using https://latexindentpl.readthedocs.io/en/latest/sec-default-user-local.html#lst-commandcodeblocksnoAdditionalIndent
for the foreach
command as demonstrated in, for example, https://latexindentpl.readthedocs.io/en/latest/sec-default-user-local.html#lst-myenv-noadd5I hope this helps, let me know if you have anything else! :)
Thank you for your depth answer. Please note that, I believe following cause was causing this output that I shared in my question.
specialBeginEnd:
If:
begin: '\\If'
middle:
- '\\ElsIf'
- '\\Else'
end: '\\EndIf'
specialBeforeCommand: 1
Would it be possible to merge it with you answer? When I keep this along with your answer I still face with the same problem
When I also added your code and experiment with following code:
\foreach \i/\j in {0.5/$H_{0}$, 1.5/$H_{0}$ } {
\node at (4.5, -\i) {\j};
}
\node[PR] at (3.48, -0.5) {\footnotesize $F^{};
\node[PR] at (3.48, -1.5) {\footnotesize $F^{};
\node[PR] at (3.48, -3.5) {\footnotesize $F^{};
\node[PR] at (3.48, -0.5) {\footnotesize $F^{};
\node[PR] at (3.48, -1.5) {\footnotesize $F^{};
\node[PR] at (3.48, -3.5) {\footnotesize $F^{};
converted into :
\foreach \i/\j in {0.5/$H_{0}$, 1.5/$H_{0}$ } {
\node at (4.5, -\i) {\j};
}
\node[PR] at (3.48, -0.5) {\footnotesize $F^{};
\node[PR] at (3.48, -1.5) {\footnotesize $F^{};
\node[PR] at (3.48, -3.5) {\footnotesize $F^{};
\node[PR] at (3.48, -0.5) {\footnotesize $F^{};
\node[PR] at (3.48, -1.5) {\footnotesize $F^{};
\node[PR] at (3.48, -3.5) {\footnotesize $F^{};
wanted output:
\foreach \i/\j in {0.5/$H_{0}$, 1.5/$H_{0}$ } {
\node at (4.5, -\i) {\j};
}
\node[PR] at (3.48, -0.5) {\footnotesize $F^{};
\node[PR] at (3.48, -1.5) {\footnotesize $F^{};
\node[PR] at (3.48, -3.5) {\footnotesize $F^{};
\node[PR] at (3.48, -0.5) {\footnotesize $F^{};
\node[PR] at (3.48, -1.5) {\footnotesize $F^{};
\node[PR] at (3.48, -3.5) {\footnotesize $F^{};
Thank you for your valuable time and help.
Happy to help :)
In your code, I see {\footnotesize $F^{};
and I think you're missing a few closing braces across a few lines.
Can you fix these and try again?
Sorry I gave you the wrong code, I was trying to simplified the code but accidently deleted \\
. Can you please have a look at to this: Having \\
as a new line in between the { }
is the main cause I believe
\foreach \i/\j in {0.5/$H_{0}$, 1.5/$H_{0}$ } {
\node at (4.5, -\i) {\j};
}
\node[PR] at (3.48, -0.5) {alper\\$\mathsf{J}$,$A$,...};
\node[PR] at (3.48, -1.5) {\footnotesize $A$};
\node[PR] at (3.48, -1.5) {\footnotesize $B$};
output:
\foreach \i/\j in {0.5/$H_{0}$, 1.5/$H_{0}$ } {
\node at (4.5, -\i) {\j};
}
\node[PR] at (3.48, -0.5) {alper\\$\mathsf{J}$,$A$,...};
\node[PR] at (3.48, -1.5) {\footnotesize $A$};
\node[PR] at (3.48, -1.5) {\footnotesize $B$};
When I use the YAML I gave above, and run
latexindent.pl -l myfile.tex
then I receive
\foreach \i/\j in {0.5/$H_{0}$, 1.5/$H_{0}$ } {
\node at (4.5, -\i) {\j};
}
\node[PR] at (3.48, -0.5) {alper\\$\mathsf{J}$,$A$,...};
\node[PR] at (3.48, -1.5) {\footnotesize $A$};
\node[PR] at (3.48, -1.5) {\footnotesize $B$};
This looks like your desired output.
To make a minimal example, make a copy of your code, and strip it down until the problem is replicated.
Interesting I am getting completely different output with following configuration, where I merge the one I give in my question with your answer:
defaultIndent: " "
verbatimEnvironments:
longtable: 1
tabularx: 1
minted: 1
item: 1
specialBeginEnd:
If:
begin: '\\If'
middle:
- '\\ElsIf'
- '\\Else'
end: '\\EndIf'
specialBeforeCommand: 1
commandCodeBlocks:
stringsAllowedBetweenArguments:
- 'in' # allows 'in' between arguments
- '\\[a-z]\/\\[a-z]' # allows any letter followed by / followed by another letter between arguments
noAdditionalIndent:
foreach:
body: 1
When I deleted following section seems like everything works fine:
specialBeginEnd:
If:
begin: '\\If'
middle:
- '\\ElsIf'
- '\\Else'
end: '\\EndIf'
specialBeforeCommand: 1
Interesting!
The problem part was the combination of
specialBeforeCommand: 1
and the default settings for inlineMath
:
inlineMath:
begin: '(?<!\$)(?<!\\)\$(?!\$)'
end: '(?<!\\)\$(?!\$)'
lookForThis: 1
which says that $
can not be preceeded by a backslash.
We can change this by using
specialBeginEnd:
specialBeforeCommand: 1
inlineMath:
begin: '(?:\\\\\$)|(?:(?<!\$)(?<!\\)\$(?!\$))' # <!------------ NEW BIT
end: '(?<!\\)\$(?!\$)'
lookForThis: 1
commandCodeBlocks:
stringsAllowedBetweenArguments:
- 'in' # allows 'in' between arguments
- '\\[a-z]\/\\[a-z]' # allows any letter followed by / followed by another letter between arguments
This says that inlineMath
can begin with
\\$
$
as long as it is not preceeded by a backslash.This gives the output
\foreach \i/\j in {0.5/$H_{0}$, 1.5/$H_{0}$ } {
\node at (4.5, -\i) {\j};
}
\node[PR] at (3.48, -0.5) {alper\\$\mathsf{J}$,$A$,...};
\node[PR] at (3.48, -1.5) {\footnotesize $A$};
\node[PR] at (3.48, -1.5) {\footnotesize $B$};
Thank you again and sorry for extending the issue with additional questions :-)
No worries, questions are welcome :) glad I could help!
Happy to help.
Can you give a complete example that demonstrates the problem?
On Sun, 21 Aug 2022, 10:31 Alper Alimoglu, @.***> wrote:
Thank you for your depth answer.
Please note that
specialBeginEnd: If: begin: '\If' middle:
- '\ElsIf'
- '\Else' end: '\EndIf' specialBeforeCommand: 1
was also causing this output that I shared in my question. Would it be possible to merge it with you answer?
— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/379#issuecomment-1221507966, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYD3DJ3IEFOYNDDHE2LV2HZNRANCNFSM57DBWHJA . You are receiving this because you commented.Message ID: @.***>
I want end bracket to be same indent with start of
\foreach
, example:yaml setting:
latexindent.pl keeps add a indent before the
}
and adds indent before the second line that follows up and also add 8 space indent inside the foreach block instead of 4 space indent.