Open kevinywlui opened 5 years ago
IMO, latexindent should be considered a fixer, not a linter!
Just want to follow up on this. I am not very experienced with vimscript, but I would be happy to write a pull request. I might need some guidance from the maintainers.
For the most part if you look at fixers that already exist you should be able to find one that is close enough to what you need, and use code from there.
So I notice that latexindent is actually already included among the tex fixers. However, when I look at :ALEInfo
, I see
(finished - exit code 2) ['/usr/local/bin/zsh', '-c', '''latexindent'' -l -w '
'/var/folders/bd/8nh4kyg933zcxm7n90n2m98r0000gn/T/nvimaLyXGD/29/algorithms.tex
''']
Would you like me to start a new issue for this?
What is the actual thing that it does to the input, and what do you expect it to do? We can rename this issue if there is an issue with it.
There is no change to the input. I expect it to make my tex file pretty. I assume that the script is failing for some reason. Maybe this helps:
❯ /usr/local/bin/zsh -c latexindent
Please enter text to be indented: (press CTRL+D when finished)
❯ /usr/local/bin/zsh -c 'latexindent -l -w /var/folders/bd/8nh4kyg933zcxm7n90n2m98r0000gn/T/nvimaLyXGD/29/algorithms.tex'
Could not find directory /var/folders/bd/8nh4kyg933zcxm7n90n2m98r0000gn/T/nvimaLyXGD/29
Exiting, no indentation done. at /usr/local/texlive/2019basic/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm line 95.
Maybe that var/
file is not accessible from the command line. Not exactly sure how that works.
That file is most likely made only for the purpose of ALE, and then afterwards deleted. What happens if you use the -l -w <filename>
options on a copy of the file?
That works.
❯ /usr/local/bin/zsh -c 'latexindent -l -w algorithms.tex'
\documentclass{article}
\usepackage{amsmath}
\usepackage{algpseudocode,algorithm,algorithmicx}
\newcommand*\DNA{\textsc{dna}}
\newcommand*\Let[2]{\State #1 $\gets$ #2}
\algrenewcommand\algorithmicrequire{\textbf{Precondition:}}
\algrenewcommand\algorithmicensure{\textbf{Postcondition:}}
\DeclareMathOperator{\softmax}{Softmax}
\begin{document}
\begin{algorithm}[H]
\caption{Current algorithm}
\begin{algorithmic}[1]
\State $s_t \gets \text{Conv}(x_t)$
\State $c_r \gets \sigma\left(\phi^{update}\left(s_t \otimes a_{t-1} \otimes
r_{t-1}^{(1)} \otimes r_{t-1}^{(2)}\right)\right)$
\State $c_g \gets \sigma\left(\phi^{update}\left(s_t\otimes a_{t-1}\otimes
g_{t-1}^{(1)}\otimes g_{t-1}^{(2)}\right)\right)$
\State $\tilde{p} \gets [0, 0, 1] \ast p_{t-1}$
\State $p_t \gets c_r\tilde{p} + \left(1-c_r\right) p_{t-1}$
\State $r_t \gets Mp_t$
\State $g_t \sim c_gp_t + \left(1-c_g\right)\text{one-hot}\left(g_{t-1}\right)$
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Counting mismatches between two packed \DNA{} strings
\label{alg:packed-dna-hamming}}
\begin{algorithmic}[1]
\State $D \gets \left(\phi^{mux}\left(\softmax\left(x_t\otimes N\right)\right)\right)$
\State $\tilde{p} \gets Dp$
\end{algorithmic}
\end{algorithm}
\end{document}
It also changes the file in place.
So you can confirm that when using the fixer, it doesn't change anything? Can you get a minimum example test-case?
Ok. This is my vimrc:
scriptencoding utf-8
set encoding=utf-8
let g:ale_fixers = {'tex': ['latexindent']}
let g:ale_fix_on_save = 1
call plug#begin('~/.vim/bundle')
Plug 'w0rp/ale'
call plug#end()
This is file:
\documentclass{article}
\usepackage{amsmath}
\usepackage{algpseudocode,algorithm,algorithmicx}
\newcommand*\DNA{\textsc{dna}}
\newcommand*\Let[2]{\State #1 $\gets$ #2}
\algrenewcommand\algorithmicrequire{\textbf{Precondition:}}
\algrenewcommand\algorithmicensure{\textbf{Postcondition:}}
\DeclareMathOperator{\softmax}{Softmax}
\begin{document}
\setcounter{algorithm}{4}
\begin{algorithm}
\caption{Counting mismatches between two packed \DNA{} strings
\begin{algorithmic}[1]
\State $\tilde{p} \gets Dp$
\end{algorithmic}
\end{algorithm}
\end{document}
Hi! I managed to make it work.
In my case ALEInfo is like this:
(finished - exit code 0) ['/bin/bash', '-c', '''latexindent'' -l /abs/path/to/latexindent.yaml -m - < ''/tmp/nvimsfgF05/5/myfile.tex'']
As you can see, ALE feeds the tex file via stream redirection. Therefore, inside the fixer there should be "-" to read the input file from stdin.
I configure fixer per project with .exrc
. If you use global latexindent.yaml, you can omit this hardcoded abspath.
So here is the part that made it work:
let g:ale_tex_latexindent_options='/abs/path/to/latexindent.yaml -m -'
let g:ale_fixers['tex'] = get(g:ale_fixers, 'latexindent', []) + ['latexindent']
fixed: However, I noticed that the output, at least for my config was different between stdin and file input: https://github.com/cmhughes/latexindent.pl/issues/493
Name: latexindent URL: https://github.com/cmhughes/latexindent.pl
This is a tool that fixes the indentation of a latex file. It can read from stdin.