How could I get an editor to align vertically by a single character in selected text? - alignment

Let's say I've got a document (it happens to be a BibTeX file) filled with thousands of entries like this:
#article{hierarchy_problem_1,
title = {Dynamics of spontaneous symmetry breaking in the Weinberg-Salam theory},
author = {Susskind, Leonard},
journal = {Physical Review D},
volume = {20},
number = {10},
pages = {2619--2625},
year = {1979},
month = {November},
publisher = {American Physical Society}
}
I want to be able to select one of those, or maybe a bunch of them, and get them to change to be aligned vertically by a single character, in this case the "=" character, so it becomes something like this:
#article{hierarchy_problem_1,
title = {Dynamics of spontaneous symmetry breaking in the Weinberg-Salam theory},
author = {Susskind, Leonard},
journal = {Physical Review D},
volume = {20},
number = {10},
pages = {2619--2625},
year = {1979},
month = {November},
publisher = {American Physical Society}
}
My editor of choice is Geany just now (which has the facility to send selected text to some external, custom command -- context menu > Format > Send Selection to) but I will entertain anything. Bearing in mind that some titles of the papers can contain the "=" character, what might be a good way to do this? I would suspect at least that the "=" character in a line after some text like "journal", would be the first instance of that character, and then it gets spaces (I'd prefer to avoid tabs) added before it in order for it to end up at, say, the 30th column. What might be some way to do this?

Maybe a shell/regex expert can build a script used in a custom command.
Personally, in your situation I will :
Set tabulation to <tab> in the document
search & replace = by <tab><tab><tab><…>=
Adjust distance with a vertical selection (need the plugin Extra Selection).

Notepad++ has an align to clipboard character.

Related

how to tokenize/parse/search&replace document by font AND font style in LibreOffice Writer?

I need to update a bilingual dictionary written in Writer by first parsing all entries into their parts e.g.
main word (font 1, bold)
foreign equivalent transliterated (font 1, italic)
foreign equivalent (font 2, bold)
part of speech (font 1, italic)
Each line of the document is the main word followed by the parts listed above, each separated by a space or punctuation.
I need to automate the process of walking through the whole file, line by line, and place a delimiter between each part, ignoring spaces and punctuation, so I can mass import it into a Calc file. In other words, "each part" is a sequence of character (ignoring spaces and punctuation) that have the same font AND font-style.
I have tried the standard Search&Replace feature, and AltSearch extension, but neither are able to complete the task. The main problem is I am not able to write a search query that says:
Find: consecutive characters with the same font AND font_style, ignore spaces and punctuation
Replace: term found above + "delimiter"
Any suggestions how I can write a script for this, or if an existing tool can solve the problem?
Thanks!
Pseudo code for desired effect:
var delimiter = "|"
Go to beginning of document
While not end of document do:
var $currLine = get line from doc
var $currChar = get next character which is not space or punctuation;
var $font = currChar.font
var $font_style - currChar.font_style (e.g. bold, italic, normal)
While not end of line do:
$currChar = next character which is not space or punctuation;
if (currChar.font != $font || currChar.font_style != $font_style) { // font or style has changed
print $delimiter
$font = currChar.font
$font_style - currChar.font_style (e.g. bold, italic, normal)
}
end While
end While
Here are tips for each of the things your pseudocode does.
First, the easiest way to move line by line is with the TextViewCursor, although it is slow. Notice the XLineCursor section. For the while loop, oVC.goDown() will return false when the end of the document is reached. (oVC is our variable for the TextViewCursor).
Get each character by calling oVC.goRight(0, False) to deselect followed by oVC.goRight(1, True) to select. Then the selected value is obtained by oVC.getString(). To ignore space and punctuation, perhaps use python's isalnum() or the re module.
To determine the font of the character, call oVC.getPropertyValue(attr). Values for attr could simply be CharAutoStyleName and CharStyleName to check for any changes in formatting.
Or grab a list of specific properties such as 'CharFontFamily', 'CharFontFamilyAsian', 'CharFontFamilyComplex', 'CharFontPitch', 'CharFontPitchAsian' etc. Character properties are described at https://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Formatting.
To insert the delimiter into the text: oVC.getText().insertString(oVC, "|", 0).
This python code from github shows how to do most of these things, although you'll need to read through it to find the relevant parts.
Alternatively, instead of using the LibreOffice API, unzip the .odt file and parse content.xml with a script.

Copy a table from iPython notebook into Word?

I want to copy a table from iPython notebook into a Word doc. I'm using Word for Mac 2011. The table is a standard pandas output and looks like this:
If I use Apple+C to copy the table, and then paste it into a Word doc, I get this:
Surely there must be an easier way?
Creating a table with the same number of rows/columns in Word and then trying to paste the cells there doesn't work either.
I guess I could screenshot the table, but I'd like to include the raw data in the document if possible.
The problem in this case (from the Word perspective) is not the table layout - it's the paragraph layout. Each paragraph has a substantial indent on right and left, and more space before/after than you would normally want.
I don't think any of the Paste options (e.g. Paste Special) in Word is going to help, unless you paste as unformatted text, then select the text, convert to a table, then proceed from there.
But, even a simple Word VBA macro such as this one will leave you with something a bit more manageable. (Select a table you copied in, then run the macro). A little bit more work on the code would probably allow you to get most of the formatting you want, most of the time.
Sub fixupSelectedTable()
With Selection.Tables(1).Range.ParagraphFormat
.LeftIndent = 0
.RightIndent = 0
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceSingle
End With
End Sub
If you are more familiar with Applescript, the equivalent looks something like this:
-- you may need to fix up the application name
-- (I use this to ensure that the script uses the Open Word 2011 doc
-- and does not try to start Word for Mac 15 (2016))
tell application "/Applications/Microsoft Office 2011/Microsoft Word.app"
tell the paragraph format of the text object of table 1 of the text object of the selection
set paragraph format left indent to 0
set paragraph format right indent to 0
set space before to 0
set space after to 0
set line spacing rule to line space single
end tell
end tell

Fill line up with special Character before and after Text

I would like to create a Sublime Text 2 Snippet that fills up the space before and after the Variable I type with spaces.
It should look like this:
===========================my_filename.js===========================
The Filename should be centered so the number of spaces before and after the Text have to match.
Also I need the overall column width of this line the stay the same. So when I add 2 Characters the number of spaces on each side gets reduced by one.
I think a sample for this would be:
spacesLeft = roundDown((columnWidth/2) - (textSize/2))
spacesRight = roundUp((columnWidth/2) - (textSize/2))
But since only RegEx is available in Sublime Snippets I don't see me able, to accomplish this task.
Could Vintagmode help me in any Way?
Thanks for your help!
Because snippets are essentially static, they wouldn't be able to help you in this case. However, you could create a plugin to do this relatively easily. Sublime Text uses python for its plugins. You can create one by going to Tools > New Plugin. ST2's API can be found here and is very impressive. Essentially, you'll want to store the current selection (your variable) using
sel_reg = self.view.sel()[0] # the current selection 'Region'
sel = self.view.substr(sel_reg) # the text within the 'Region'
Then generate the ='s
signs = ''
each_side = len(80 - len(sel))/2 # 80 is the standard window length,
# change this to what you want.
# Not sure about how to make it dynamic.
for x in xrange(each_side):
signs += '='
Then replace the current line (self.view.line(sel)) with signs + sel + signs.

How to preserve quotes in BibTeX

I'm new to LaTeX and BibTeX, so excuse my ignorance. I have the following entry:
#Article{Hart,
author = {P.E. Hart, N.J. Nilsson, B. Raphael},
title = {Correction to \"A Formal Basis for the Heuristic Determination of Minimum Cost Paths\" },
journal = {SIGART Newsletter 37},
year = {1972},
pages = {28-29}
}
But this comes out as a capital letter A with diaeresis (Ä) and a ':', respectively. How do you get BibTeX to display quotes in a title?
First, quotes should be done like ``this'' (with back-ticks and apostrophes). Second, wrapping this in braces {like this} protects it from being messed with by bibtex. (You need to do this to get capital letters in article titles, for instance.

Capital in Bibtex

I want to show some letters in Bibliography as capital. For example:
#misc{libsvm,
abstract = {LIBSVM is an implbmentation of Support vector machine (SVM).},
author = {Chang, Chih-Chung},
howpublished = {\url{http://www.csie.ntu.edu.tw/~cjlin/libsvm/}},
keywords = {svm},
posted-at = {2010-04-08 00:05:04},
priority = {2},
title = {LIBSVM.},
url = "http://www.csie.ntu.edu.tw/~cjlin/libsvm/",
year = {2008}
}
But "LIBSVM" is not shown as it is:
[3] Chih-Chung Chang. Libsvm. http://www.csie.ntu.edu.tw/ ̃cjlin/libsvm/,
2008.
How can I make the letters capital? Thanks and regards!
Generally, to keep BibTeX from turning your letters lowercase, enclose them in {}:
title = {A History Of {StudlyCaps}}
will produce "A history of StudlyCaps."
Alceu Costa is correct that all-capital abbreviations should be formatted in small capitals, but that is a different matter than this.
The \textsc is used to format the text in small capitals. You can do this in your .bib file:
title = {\textsc{LIBSVM}}
Place {} brackets around anything you want to keep in CAPS.
For example:
#type{bibkey,
title = "{M}y {B}ibliography is the {B}est!",
author = "{ABCDE}",
}
In the case of IEEEtran LaTeX Class template, one can simply do the following:
title = "{3D Open Source Framework for Something you need}"
A template can be found at the following link
http://www.ieee.org/conferences_events/conferences/publishing/templates.html

Resources