-
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
Environments should be put on their proper lines in input #815
Comments
I am a bit reluctant to force the user to have a newline. |
Do we agree this:
|
but it could also be turned into It really depends on the width of the screen where the user edits the tex source and his own taste. But it must be designed well with regard to usability in order to avoid complicating things and making them more difficult for the user. |
I think it is better not to hurry with the implementation but rather decide on a nice design (usability-wise) |
As I said: "Every environment [...] I can think of puts its content on proper lines in output so every environment should be put on their proper lines in input." So, if
which is closer from the output.
Indeed and the latter code is okay for screens of large and small widths.
Indeed, and I guess the current behavior isn't to the taste of many users who have to manually rearrange the resulting code to make it more readable.
Why not. But, IMO, the layout I suggest should be the default, and such a configuration should be considered as a (very) advanced option. |
TeX does not have a one to one correspondence between the formatting of the source and the formatting of the compiled document. IMHO many authors don't really bother about the formatting of the source and just prefer the document source to be short, so having everything just on one line should be an option too. I think it would be better to avoid specialized changes and to have a well thought-out and configurable approach to formatting the source. So maybe this should be added an enhancement tag but implemented in more generic fashion once we have a clear idea how to organize everything to make it usable and generic. |
First, for very rare cases (mostly some verbatim environments), a newline before or after the
Second, there are more details to consider: If we expect % use >>text<< to express that "test" is selected
abc >>def<< ghi
->
abc<space>
\begin{center}% % insert two newlines, before and after
def% % add indent or not?
\end{center}% % insert two newlines
<space>ghi then do we also expect abc
>>def<<
ghi
->
abc
\begin{center}% % insert only one newline
def
\end{center}% % insert only one newline
ghi Also, I checked how does "wrapEnv": {
"body": "\n\\begin{$1}\n\t${TM_SELECTED_TEXT}\n\\end{$1}",
"description": "Wrap selection into an environment"
}, This shows that The reference from (This comment should have been posted several hours ago, if I have not mistakenly closed my browser tags.) |
I agree. But, IMO, having an input evoking the output helps when one needs to revisit his source. And there is a famous example of (I'm pretty sure) intentional input evoking output provided by (La)TeX: empty line(s) being an alias of
Well, I'm not sure. Or if they don't bother, they fail to realize this complicates their lives :)
Why not, but this would be a long term project. Meanwhile, some users will continue to be annoyed by messy formatted inputs such as: test \begin{center}
foo
\end{center} bar |
@muzimuzhi About verbatim environments, indeed some care is needed.
I'm supporting the indentation and I would expect the (irrelevant)
That's what I would expect. |
Maybe it would be better to have some generic rules for the source code formatting and maybe some kind of menu option to reformat the .tex source code (something like an improved version of indent/unindent). |
Yes, this is what I meant by "source code formatting". All modern development environments allow to reformat the selected source code or the whole file if there is no current selection. |
Actually I think this can be implemented by some kind of macro script. |
@MeanSquaredError Do you mean it shouldn't be a feature provided by default by TXS? |
I think it should be a feature coming with the default installation of TXS, just implemented through scripting. It would be faster to implement and more reliable (if there is some bug it would have good chances of crashing just the script instead of the whole TXS). |
Actually I think that more TXS features can (and probably should) be implemented through scripts. For example the the more complex table manipulation features in the wizards that we discussed a few issues ago probably can be implemented through scripts. AFAIK the TXS scripts are some dialect of JavaScript so it would be easier to prototype the code in JS than in C++. |
TXS uses QtScript, however that is not actively developed anymore. While it's said to not go away sooln, I wouldn't build new code on that. An alternative is QJSEngine, but that is Qt5 only (we would have to cut Qt4 compatibility. I'm not really attached to that, so maybe ok). Another alternative would be to embed a Python interpreter. This would allow to take advantage of existing libraries like https://github.com/sciunto-org/python-bibtexparser to add functionality we're currently missing (e.g. a tabular view of the bibtex entries or nicely formatted tooltips for bibtex entries). I think it suits well for parsing (thinking of importing a table into the table wizard. Also, chances are good, that users (many of whom are scientists) know Python already and it could become a public scripting API some day. |
After some googling I came across Another option would be to embed the Python interpreter directly without any 3rd party library as they do it here:
|
using script in txs is totally fine. The table manipulation code uses it as well. I would discourage to go for python or any other (external) script language. txs is already complicated enough to maintain on different platforms and especially windows will make things complicated with external dependencies... And last, probably we can cut qt4 support as libpoppler-qt4 is not delivered any more on current platforms and thus txs can not be built there with all (main) capabilities. The qt4 already has some reduced functionality. |
I googled a bit and it seems to me that the switch from QtScript to QJSengine should be invisible to the TXS users and any scripts should remain working. I will try to find time in the next couple of weeks to implement a basic .tex source (re)formatter in QtScript |
3./4. Not really looked into the details of Python embedding. This is more of an idea for the long-term. PythonQt is indeed what comes up first, but seems not quite active. Blender is one of the largest projects using Python as a scripting language for Qt (I haven't had a look how they do it either). With the adoption of PySide2/Qt for PYthon, Continuum has declared Python as first class language for Qt. Though I haven't heard anything in that direction, it would be a logical step to make it available as a scripting engine in the future. |
I guess in the short and mid-term we will just switch to QJSEngine and will get rid of the old QtScript. In the long term I can imagine some kind of plugin architecture where the main TXS core will contain some kind of abstraction layer that will allow plugging in different scripting languages. The main language will be QJSEngine, but there will be additional languages implemented as plugin modules. This will allow implementing these additional languages separately (possibly as separate git subprojects) without messing up too much with the main core. Of course all of the above are just some generic ideas (food for thought). |
Related: #177. |
I could not find time to work on this fulltime, but I have been working on it now and then for a couple of months. Did a few standalone implementations in QtScript that did not work very well, because one really needs the syntax information from the tokenizer and re-implementing a tokenizer from the scratch in QtScript is no fun :-) Finally I settled on a combined implementation in C++ (which exports the tokens from the C++ tokenizer) + the high level code in QtScript which does the parsing. Hopefully will be able to provide a PR in about a week or so. |
@dbitouze @muzimuzhi |
I already advocated Maybe your expertise, as the |
Happy to help if I can :)
…On Mon, 29 Mar 2021, 20:25 Denis Bitouzé, ***@***.***> wrote:
Latexindent does this, see
https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#adding-line-breaks-beginstartsonownline-and-bodystartsonownline
I already advocated latexindent here
<#177>, unfortunately
without much success.
Maybe your expertise, as the latexindent developer, could help in the
process of smoothly integrate it into TeXstudio 😄
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#815 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQ7CYGYSDQIXFIEOUWOPKDTGDO4NANCNFSM4JRWNGUA>
.
|
Another possibility might be to make use of the code formatter |
Environment
Feature request
Every environment (properly used, e.g.
tiny
environment shouldn't be used) I can think of puts its their content on proper lines in output so every environment should be put on their proper lines in input. For instance, consider:test foo bar
and suppose you decide to center "foo". With TXS, you select it and click on the relevant button and now you get:
which is less readable than:
More precisely, if it is possible for TXS to know if what is selected (possibly empty) is the whole line, I would suggest to put the
\begin{env}
on a new line only if it is not the case. To be more specific:Empty preselection: the environment is inserted on the current line.
results in:
Whole line (here, "content") preselected: the environment is inserted on the current line.
results in:
Subset of line (here, "content") preselected: the environment is inserted on a new line.
results in:
The text was updated successfully, but these errors were encountered: