Posts

Showing posts with the label Regex

Automatic generation of hyperlinks in LaTeX environment, using Vim's Regular Expressions, between PDF documents.

Image
Vim is an editor with endless capabilities. It can also generate hyperlinks in LaTeX language to other locally stored documents, thanks to its built-in Regular Expressions. For lawyers, this means linking a legal document with its related evidentiary materials. This is the analysis of the procedure. 1. Subject of this article. 2. Main document configuration. 3. RegEx formula for automatic link generation. 4. Explanation of the RegEx formula. 5. Management of "underline character". 6. Links within the text 6.1. "Indirect linkage" solution: 6.2. "Direct link" solution: 1. Subject of this article. Sometimes it is necessary to include in a main PDF document a list of documents to be retrieved with specific hyperlinks dedicated to each item in the list. For example: judicial acts with reference to related document productions. In this article I deal with the automatic generation of hyperlinks in LaTeX by Vim using...

Linux: rename, rename.ul, prename, perl-rename: what a confusion!

Image
1 Summary of this article. 2 One for all: mv . 3 The rename command: this is where the problems begin! 4 How does the rename command behave that is NOT compatible with regular expressions? 5 The regular expressions compatible commands. 6 The “ sed ” command in GNU/Linux. 7 Using regular expression compatible commands. 1 Summary of this article. In this article I report some observations on how to rename documents in GNU/Linux using text commands, clarifying some differences between various distributions. The rename command does not, in fact, have unique behavior in distributions derived from Debian versus those derived from Fedora and Arch. I will try to clarify the content of different commands and the different behavior of commands that have the same name. All steps were personally tried during the writing of the article. If you find inaccuracies or errors, please let me know. 2 One for a...

Powerful OCR system under GNU/Linux for PDF documents managed from command line and with refinement by Vim.

Image
1 Introduction. 2 The installation of components. 3 OCR of PDF documents with “tesseract”: description of steps. 4 The single steps. 5 Everything in one command! 6 And now: Vim with RegEx. 7 In Conclusion. {{% toc %}} 1 Introduction. The idea came from reading this article about optical character recognition (OCR) in the GNU/Linux environment from images and PDF, managed from the command line. Obviously, PDF documents are those scanned from paper original, i.e., not obtained by direct saving of document in digital format. For the latter, no OCR is needed. The article is very well written and the end result is very good. I wondered if it would be possible to aggregate all the steps into a single text command. In this article I report my solution. Next, then, I added some con RegEx steps by Vim to reformat the raw result of optical recognition. Again, I tried to combine several separate formula...

Vim Is Magic or Nomagic?

Image
What’s this joke? The title is a joke with the name of “ V.I.M. ” but, at the same time, it’s a real mode of Vim itself: the Magic Mode . To understand what Magic Mode is, the primary source is the item :help magic in Vim. In a few words: - The Magic Mode refers to the regular expressions - The Magic Mode is enabled by default in Vim. - You can explicitly invoke the Magic Mode with the \m command in the RegEx search area. - To deactivate it you must set \M (capitalized m ) in the RegEx search area. - When you use the \M command you invoke the Nomagic Mode . - Nomagic Mode turns “ almost all special regex symbols into ordinary ones unless they start with a backslash ”. - There is also a Very Nomagic Mode that extends the effect to other characters, not relevant to this article. When is magic mode (default) better than nomagic? To analyze the difference between magic and nomagic mode, I resume a formula from a previous article of mine . It’s the Vim RegEx formula for...

Vim: study on transposing lists of names from horizontal to vertical

Image
Primary purpose of the study. Initial status : series of inline names, separated by a semicolon followed by a space. Objective : Transpose all names into one column by removing both semicolons and spaces. Purpose : Creating list for mail-merging with e-mail client ( Thunderbird ). Tools : Vim and built-in RegEx function. Example : From: One@mail; Two@mail; Three@mail; ... To: One@mail Two@mail Three@mail ... Secondary goal To test the integration between Markdown and css tags. This objective was accomplished in the Example above by inserting the following code: <p style = "text-align: center; font-weight: bold;" > Da: </p> <pre> One@mail; Two@mail; Three@mail; ... </pre> <p style = "text-align: center; font-weight: bold;" > A: </p> <pre> One@mail Two@mail Three@mail ... </pre> Vim: regular expression for the primary target To obtain the transposition from horizontal to vertica...

Comparison of Vim and Emacs for a substitution operation using regular expressions

Image
Preface This article is a summary of two previous posts that you can read at these pages: “Vim: Study on constructing Regular Expressions to delete or reduce blank lines with Global Command” “Emacs: Study on constructing Regular Expressions to delete or reduce blank lines” The topic of “regular expressions” in Vim and Emacs is well suited for a functional comparison across the four different scenarios covered in the above articles to which I refer for a description of the syntax. Comparation Table Target Vim Emacs Delete “pure” blank lines :g/^$/d M-x flush-lines <RET> ^$ <RET> Delete blank lines with whitespace :g/^\s*$/d M-x flush-lines <RET> ^\s-*$ <RET> Reduce “pure” blank lines :g/^$\n^$/d M-x query-replace-regexp <RET> ^C-qC-j\{2,\} <RET> C-qC-j <RET> Reduce blank lines with whitespace g/^\s*$\n^\s*$/d ^\(^C-q<SPC>*C-qC-j\)\{2,\} <RET> C-qC-j <RET> Emacs: what you type is n...

Emacs: Study on constructing Regular Expressions to delete or reduce blank lines

Image
After writing an article focusing on “Vim: Study on constructing Regular Expressions to delete or reduce blank lines with Global Command” I tried to match with a similar operation with Emacs. The goal is to study the differences in syntax related to “regular expressions” between two writing systems. The following is the result of my attempts after various searches on the net. Removing blank lines in Emacs using RegExp First of all, it may be useful to display the blank lines in the document. To preview blank lines, you can use the whitespace-mode function ( M-x whitespace-mode <RET> ): blank lines will be marked with dollar signs, i.e., lines in which there is no character, not even white space. At this point you can select a region or operate on the entire document from the cursor point with the flush-lines function, or the alias delete-matching-lines , to remove lines that match a search command: M-x flush-lines <RET> ^$ <RET> The formula’s meaning is a...

Vim: Study on constructing Regular Expressions to delete or reduce blank lines with Global Command

Image
Preface On the topic of this article you may find interesting the following one: “Vim and Regular Expressions for removing redundant whitespace” . Unlike the previous article, here the presence of whitespace causes different solutions than blank lines regardless of the number of their occurrences. The study in this article is focused on both the analysis of “ regular expressions ” and Vim’s global command. Vim and the Global Command The Global Command in Vim is the g key. It’s useful for a lot of purposes. In Normal Mode it can be used to compose multi-letter commands, such as the following ones: guw : lower case next word gUw : upper case next word gU2w : upper case next two word gUe : upper case until the end of the word gu$ : lower case until the end of the line ge : move to the end of the previous word (simple e moves to the end of the next word) … and so on. The g Command can also be a motion operator , as described in this article of mine . The same global ...

Vim and Regular Expressions for removing redundant whitespace

Image
Introduction and structure of the article I wrote this article to practice “in situ” formula construction of Regular Expressions , also called "RegEx", in Vim. In particular, the goal is to “clean up” documents with excess whitespace at both the beginning and end of each line. A basic knowledge of Vim and the Regular Expressions built into the editor is sufficient for understanding the article. The various formulas are applied to whole documents but, since they are very normal search commands in Vim, they can be applied to individual rows or to specific ranges of rows in the context of the document. There are three formulas illustrated and the construction is progressive with “step-by-step” analysis of the syntax of Regular Expressions . The structure of the article is as follows: first I illustrate the creation of the formula for an end-of-line operation; then I move on to the reverse formula, i.e., for the same operation but at the beginning of the line; finally ...

Vim: two methods to append blank lines under multiple text lines

My Table of Contents What are we talking about? The Regular Expression solution The Global Command solution