-
Notifications
You must be signed in to change notification settings - Fork 351
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
TeX source-formatting script #957
Comments
you can add it to texstudio-macro which makes import even simpler ... |
OK, I created a PR with this script in the texstudio-macro repository. |
The script seems to destroy my text, see issue |
The issue should be fixed now. The script that is attached to this post is already obsolete, but the latest version can be downloaded from the TXS menu |
@MeanSquaredError Many thanks for the work on this subject! From: \documentclass{article}
\begin{document}
Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
\end{document} I get: \documentclass{article}
\begin{document}
Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
\end{document} whereas I would expect: \documentclass{article}
\begin{document}
Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla
\end{document}
Am I missing something? |
The script assumes soft line wrapping and from your output it seems that you are using hard line wrapping. Regarding the indentation - the latest version of the script supports a list of environments for which no indentation should be applied. By default it applies indentation to all environments. The script posted at the beginning of this issue is an old version, but you can get the latest version of the script either from the TXS builtin script importer or from
I will try to update the script so that it will autodetect the line wrapping settings and will split the lines if hard line wrapping is configured. Hopefully it should happen in the next couple of days :-) |
Nothing escapes you! 😄
Do you mean Macros → Edit Macros → Import? If I click on the latter, it just opens my File Manager...
OK, done! 😄
Thank you very much! |
@dbitouze However if you already got the script from my github account then you are already settled, since it is the latest version of the script anyway. |
You're welcome!
Okay. This way of updating remote macros is far from obvious: is some more straightforward way planned? |
This mechanism for macro updates has been there for a while (definitely before I started submitting TXS patches), what it does effectively is that it allows the user to fetch macros from I am not really familiar with any plans for any changes to this macro update feature. My guess is that there are no specific plans for any changes to it. However I think that any comments/suggestions are welcome (whether they will be implemented is another matter and depends mainly if there will be someone willing to work on the suggestions :-) |
OK, I implemented support for hard line wrapping in the source formatting script. Now it will autodetect the configured line wrapping mode and will format the source accordingly. It has not been uploaded to the |
@MeanSquaredError With:
and the new version of the script (526 lines), I still get the text on a single line. I don't know how to debug in order to help you: maybe my |
Yes, please upload you For the new script to split the text on multiple lines it need the following settings: |
Hum! Sorry for the noise:
With the settings you specified (and that are obvious), it works nicely! Hence, maybe a warning could be emitted if the required settings are not fullfilled |
@dbitouze I guess I could add an additional configuration option that would allow the user to specify explicitly way text is handled instead of using the TXS settings. |
OK, I added support for configurable column number after which hard line wrapping occurs. The configuration setting is specified
The latest version of the script can be downloaded from https://github.com/MeanSquaredError/texstudio-format-source/blob/master/scripts/format_source.txt but I also sent a PR to texstudio-macro, so it should appear there as well in a day or so. |
@MeanSquaredError Works nicely, thanks! Nevertheless, I would again emphasize that this should be a built-in feature of TXS: it is such a pain to localize (La)TeX errors in too long lines... |
@dbitouze
|
;) IMHO, users don't know they need this killing feature because they think looking for (La)TeX errors in veeeeeeeeeeeeery long lines, just as looking for a needle in a haystack, is just a normal inconvenient of LaTeX.
Damn! :)
I can understand.
The point is how to warn them about the necessity to vote for this feature request :$ BTW, maybe the current macro could be extended or, rather, changed to format only the current selected portion of text. Hence users wouldn't complain that all the 5749 lines of their document has been formatted by error... |
@dbitouze |
I finished implementing the first proof-of-concept TeX source-formatting script. The script requires a recent development version of TXS (3.0.0-git) because it uses the new
document.getLineTokens()
method.It is implemented as a .txsMacro so it can be imported from
Macros/Edit Macros.../Import
It can be used by opening a .tex document in the editor and then starting the imported macro from the
Macros
menu item.I am pretty sure that it has quite a few rough edges, since it is the very first version and I only gave it very limited testing. So any testing and feedback are welcome!
format_source.txsMacro.txt
The text was updated successfully, but these errors were encountered: