So I'm writing my bibliography in LaTeX using the following setup. However my references come out in a sort of 'newspaper style'. By this I mean the spacing between the words spreads out for them to fit the line, which leaves massive gaps between some of the names. I just want it to stay together like normal text. My document style is 'report'.
\begin{thebibliography}{1}
\bibitem{}
.
.
.
\end{thebibliography}
To avoid big horizontal gaps in it, the bibliography is sometimes preferred to be not justified (while the body of text normally is). One basic way to do this in your setup is:
\begin{flushleft}
\begin{thebibliography}{1}
\bibitem{} ...
.
.
.
\end{thebibliography}
\end{flushleft}
Related
I'm trying to take a screenshot of some minified js code so that I can print it onto something. I'm having trouble finding an editor/IDE that can wrap the text properly.
Notice how the right side is jagged because it only wraps after a complete word.
What I'm trying to achieve
https://alpha.wallhaven.cc/wallpaper/120534
Is there a text editor/plugin that lets me wrap text mid-word like this?
I suggest using vim. It wraps the text half way through a word by default but you can configure it to break on spaces using the :set linebreak command.
I'd like to use vim to edit long texts (prose / no code), in a well formatted way.
Let consider this file:
I can use sentences, paragraphs, etc. vim's features but the long sentences formatting isa bit ugly/poor readable.
So I'd like to have a some justification alignement with strict fixed colums width (let say columns = exactly 100).
I done some tests instlalling par unix command line utility (sudo apt-get install par) and setting vim to use it (with 'justify' flag):
:set formatprg=par\ jw100
and doing vim command:
gqG
but without a perfect joy, see screenshot here:
as you see I don't have an exact justification to 100 chars.
why ?! It could be depend because par do not recognize some >8bit chars (of Italian language text here) ?
In fact there is a second issue: I don't want to permanently convert the original text in an aligned elaboration that destroy original sentence (introducing blanks/new line), but i would just VIEW the text leaving the original text untouched. There is a way to do that formatted view mode ?
Vim has :set wrap, and that's it. Remember, it's not a WYSIWYG editor, so viewing as justified text is out of scope.
You would indeed have to convert the physical text (back and forth). If the par utility doesn't work (I think it should deal with UTF-8 encoded text; check your $LANG value for that), you could also give the $VIMRUNTIME/macros/justify.vim script that ships with Vim a try.
To temporarily use par on your file, make sure you've saved with :w and then use :!par jw100 <% | less, it will show you a readonly scrollable 100-char justified version of your file. When you are done, hit q and then Enter
Here's an example on some Lorem Ipsum text:
I would like to define a text object like iw, aB and the other ones listed in :help text-objects that defines an area beginning with some pattern and ending with another. More precisely, I would like to define a text object which starts with some {pattern1} and ends with some {pattern2}. The patterns included. It is important that it can stretch over multiple lines (like aB but unlike a").
The examples I have in mind are for selecting in-line equations in LaTeX, that is, everything between one $ and the next $ (including the $'s), and for selecting LaTeX environments like between \begin{*} and the following \end{*}, where the * here is just any string of characters (but non-greedy like \{-} in Vim regex).
I have tried to tried to look at this guide at the Vim Tips Wiki, but I do not know how to replace [z and ]z with something that searches backwards for some pattern and forwards for some patters, respectively, so that it works as I want it to.
So to give the example of the inline equation (lets say the text obejct is called ad), then, if the cursor was placed somewhere between the $'s in the following line:
it follows that $ \sum_{n=0}^\infty 2^{-n} $ is two
in normal mode, and vad was pressed, then $ \sum_{n=0}^\infty 2^{-n} $ should be in visual, or if dad was pressed it should be deleted.
The mentioned Vim Tips Wiki page lists the two plugins (under "Related scripts") that make defining new text objects very easy:
textobj-user is very flexible and generic
CountJump plugin (by me) is specially written for text objects defined by start and end patterns
The following call defines an ad text object for text inside $...$:
call CountJump#TextObject#MakeWithCountSearch('', 'd', 'a', 'v', '\$', '\$')
How would you use VIM to delete a word group, which includes white space characters, but is a standard grouping you would want to access when scripting? Specifically, when you have your cursor over some part of the following text, how would delete help="initialize, lines, h2, derivs, tt, history", from below. Maybe one would need to create specific mappings. But on the other hand, it seems pretty natural to want to access text like this if you are using VIM to edit scripting programs.
parser = argparse.ArgumentParser()
parser.add_argument("task", help="initialize, lines, h2, derivs, tt, history", default='yes')
Vim has a variety of text objects built-in, e.g. da" deletes quoted text (including the quotes; di" keeps the quotes). See :help text-objects for more information.
There are some plugins, e.g. textobj-user - Support for user-defined text objects and my own CountJump plugin that make it easy to define your own, "special" text objects. Also, you'll find many such text objects on vim.org. Based on your example, argtextobj.vim - Text-object like motion for arguments may be exactly what you need here.
If you are inside the " you want to delete, I would use:
di"diW
If you were above help=, I would use something like:
d/defEnter
to remove everything until you encounter default, followed by a few x, and left-wise motion, to remove the remaining characters.
I don't really think a new mapping is needed, but your experience may vary.
What makes sense from Vim's perspective and according to its design goals is to provide small and generic elements and a few rules to combine them in order to achieve higher level tasks. It does quite a good job, I'd say, with its numerous text-objects and motions but we always have to repeat domain-specific tasks and that's exactly where Vim's extensibility comes into play. It is where users and plugin authors fill the gap with custom mappings/object/functions and… plugins.
It is fairly easy, for example, to record a macro and map it for later reuse. Or create a quick and dirty custom text-object…
The following snippet should work with your sample.
xnoremap aa /\v["'][,)]/e<CR>o?\v\s+\w+\=<CR>
onoremap aa :normal vaa<CR>
With it, you can do daa, caa, yaa and vaa from anywhere within that argument.
Obviously, this solution is extremely specific and making it more generic would most certainly involve a bit more thought but there are already relatively smart solutions floating around, as in Ingo's answer.
I'm thinking of translating a book from English to my native language. I can translate just fine, and I'm happy with vim as a text editor. My problem is that I'd like to somehow preserve the semantics, i.e. which parts of my translation correspond to the original.
I could basically create a simple XML-based markup language, that'd look something like
<book>
<chapter>
<paragraph>
<sentence>
<original>This is an example sentence.</original>
<translation lang="fi">Tämä on esimerkkilause.</translation>
</sentence>
</paragraph>
</chapter>
</book>
Now, that would probably have its benefits but I don't think editing that would be very fun.
Another possibility that I can think of would be to keep the original and translation in separate files. If I add a newline after each translation chunk and keep line numbering consistent, editing would be easy and I'd be able to programmatically match the original and translation.
original.txt:
This is an example sentence.
In this format editing is easy.
translation-fi.txt:
Tämä on esimerkkilause.
Tässä muodossa muokkaaminen on helppoa.
However, this doesn't seem very robust. It would be easy to mess up. Probably someone has better ideas. Thus the question:
What would be the best data format for making a book translation with a text editor?
EDIT: added tag vim, since I'd prefer to do this with vim and believe that some vim guru might have ideas.
EDIT2: started a bounty on this. I'm currently leaning to the second idea I describe, but I hope to get something about as easy to edit (and quite easy to implement) but more robust.
One thought: if you keep each translatable chunk (one or more sentences) in its own line, vim's option scrollbind, cursorbind and a simple vertical split would help you keeping the chunks "synchronized". It looks very much like to what vimdiff does by default. The files should then have the same amount of lines and you don't even need to switch windows!
But, this isn't quite perfect because wrapped lines tend to mess up a little bit. If your translation wraps over two or three more virtual lines than the original text, the visual correlation fades as the lines aren't one-on-one anymore. I couldn't find a solution or a script for fixing that behavior.
Other suggestion I would propose is to interlace the translation into the original. This approaches the diff method of Benoit's suggestion. After the original is split up into chunks (one chunk per line), I would prepend a >> or similar on every line. A translation of one chunk would begin by o. The file would look like this:
>> This is an example sentence.
Tämä on esimerkkilause.
>> In this format editing is easy.
Tässä muodossa muokkaaminen on helppoa.
And I would enhance the readability by doing a :match Comment /^>>.*$/ or similar, whatever looks nice with your colorscheme. Probably it would be worthwhile to write a :syn region that disables spell checking for the original text. Finally, as a detail, I'd bind <C-j> to do 2j and <C-k> to 2k to allow easy jumping between the parts that matter.
Pros for this latter approach also include that you could wrap things in 80 columns if you feel like I do :) It would still be trivial to write <C-j/k> to jump between translations.
Cons: buffer-completion suffers as now it completes both original and translated words. English words don't hopefully occur in the translations that often! :) But this is as robust as it gets. A simple grep will peel the original text off after you are done.
Why not use a simplified diff format?
it is linewise which is suitable for whole sentences.
The first character is significant (space, special, + or -)
It will be quite compact
Maybe you needn't those ## parts
Vim will support it and color the English sentence and the Finnish sentence in distinct colors.
Assuming you want to keep the 1 - 1 relationship between the original text and the translated text, a database table makes the most sense.
You'd have one table with the following columns:
id - Integer - Autonum
original_text - Text - Not null
translated_text - Text - Nullable
You'd need a process to load the original text, and a process to show you one line of the original text and allow you to type the translated text. Perhaps the second process could show you 5 lines (2 before, the line you want to translate, and 2 after) to give you context.