3

While using git and other versioning systems, it is very useful that text lines occupy no more than (say) 80 characters. It is also more comfortable to edit text with vi if lines are note excessively long.

I like to write my text so that each sentence begins in a new line, e.g.,

The design of a programming language is a delicate art of balancing 
  between conflicting trade-offs. 
On the one hand, to make the language appealing, the language 
  designer would like to equip future programmers with a variety 
  of powerful and useful abstractions. 
On the other hand, the folk-lore of language design is that any 
  feature added to a language collects its tolls. 
Such tolls may result in reduced elegance of the design,
  a steeper language learning curve, 
  and complication of the construction of language processing tools.

My co-author, who uses TeXMaker favors the convention of one line per paragraph. The above would look like

The design of a programming language is a delicate art of balancing    between conflicting trade-offs.  On the one hand, to make the language appealing, the language designer would like to equip future programmers with a variety of powerful and useful abstractions.  On the other hand, the folk-lore of language design is that any feature added to a language collects its tolls.  Such tolls may result in reduced elegance of the design, a steeper language learning curve, and complication of the construction of language processing tools.

What are the prospects of an attempt to implement a script to convert back and through the two conventions automatically? The main difficulty, so I believe is to identify periods, or other punctuations that end sentences. Dealing with parenthesized sentences etc. Ignoring the most frequent LaTeX macros would also be handy.

  • Organize a cagefight and whoever wins gets to determine the writing conventions ;-) Writing a script to do this reliably will be difficult − though not impossible − but probably outside the scope of an answer... – Martin Tournoij Mar 28 '16 at 14:40
  • The co-author is muscular student. I would not want to go into a fight nither with muscular nor with student. Would it make sense to do this semi-automatically? A script that would approximat this conversion would be great. – Yossi Gil Mar 28 '16 at 14:43
  • Approximating could probably be done by using gq to break the lines, and J to join the lines back together. vipJ will run J on the "inner paragraph". – Martin Tournoij Mar 28 '16 at 14:46
  • gq is not a good idea in terms of git. Every little change in a paragraph will confuse git – Yossi Gil Mar 28 '16 at 14:57
  • Suggest a different "fight": each of you should try to make a method to only convert the input text from the other format into the preferred one, using the scripting capabilities of the editor used. So you can use Vim, and he can use TeXMaker. And each keep a different git revision, in the preferred format. – VanLaser Mar 28 '16 at 21:49
3

This is a question that is difficult to write a very rigorous answer to. But I find it easy to state that the prospects are not quite good. At least not if you try to include the corner cases.

As you say, you must identify periods and punctuations, but you should also parse many macros, such as \emph{...}, and you should parse stuff like some text {\macro more text} here. You must also allow inline math ($...$ or \(...\)), and you must deal with equations that are "part of" the sentence, e.g.

Consider $f$, where
\begin{equation}
f(x) = 1,
\end{equation}
and so on.

So, my point is that your script should in generally handle a lot of rather complicated stuff. I've written a lot of code for parsing LaTeX while working with vimtex, and my experience is that this problem is very non-trivial. To be more specific, I've written a custom formatexpr, see autoload/vimtex/format.vim in the vimtex repo. This formatexpr allows one to format LaTeX paragraphs with gq. Without this, Vim would include equations and similar environments, and so the paragraphs become "garbled". My point is that even though the function is quite simple, I found it quite difficult to write. And the current version only handles the case where text is hardwrapped at a given column number.

With that said, I also want to point out that I don't think this is impossible either. Just difficult.

Finally, my suggestion is therefore instead to agree with your student on a single convention. And I think one line per sentence is the smarter choice, since it makes it more convenient to view diffs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.