alin/Split rectangle nodes in tikz ( LaTeX)
\usetikzlibrary{shapes}
\begin{tikzpicture}
\node [shade, rounded corners, draw=black!60, rectangle split, rectangle split parts=3, text ragged] {
\textbf{Title}
\nodepart{second}
A
\nodepart{third}
B
};
\end{tikzpicture}
alin/connect different tikz pictures on the same page ( LaTeX)
\usetikzlibrary{shapes}
\tikzstyle{every picture}+=[remember picture]
\begin{tikzpicture}
\node (a) at (0,0) [rectangle, draw] {};
\end{tikzpicture}
abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc
\begin{tikzpicture}
\node (b) at (0,0) [circle, draw] {};
\end{tikzpicture}
\begin{tikzpicture}[overlay]
\draw (a) -- (b);
\end{tikzpicture}
[overlay] tells Tikz not to compute a bounding box for the picture. Otherwise the bounding box will include all referenced nodes
alin/various arrow tricks between nodes in tikz ( LaTeX)
\usetikzlibrary{arrows}
\begin{tikzpicture}[font=\scriptsize]
\node (a) at (0,0) [circle, draw] {a};
\node (b) at (1,1) [circle, draw] {b};
\draw (a) to[bend left] (b)
(a) to[bend right] (b);
\draw [dashed] (a) |- (b);
\draw [red,->>] (a) -| (b);
\draw [xshift=2pt] (a) -- (b);
\draw [xshift=-2pt] (a) -- (b);
\node[rectangle,draw] (A) at (.5,.5) {A};
\node[rectangle,draw] (B) at (3,1.5) {B};
\node[rectangle,draw] (C) at (.5,-2) {C};
\draw[-left to] (A.north east) -- (B.west);
\draw[-left to] (B) -- (A);
\draw[->] (A.280) -- (C.80);
\draw[<-] (A.260) -- (C.100);
\end{tikzpicture}
alin/lines crossing each other (and making way for each other) in tikz ( LaTeX)
\begin{tikzpicture}[cross line/.style={preaction={draw=white,->,line width=6pt}}]
\node (S) at (0,0) {a};
\node (2) at (0,4) {b};
\node (P) at (4,0) {c};
\node (P2) at (4,4) {d};
\node (w) at (2,2) {a1};
\node (W) at (2,6) {b1};
\node (Pw) at (6,2) {c1};
\node (PW) at (6,6) {d1};
\draw[->](S) -- (2);
\draw[->](S) -- (P);
\draw[->](P) -- (P2);
\draw[->](w) -- (W);
\draw[->](w) -- (Pw);
\draw[->](W) -- (PW);
\draw[->](Pw) -- (PW);
\draw[->](S) -- (w);
\draw[->](P) -- (Pw);
\draw[->](2) -- (W);
\draw[->](P2) -- (PW);
\draw[cross line,->] (2) -- (P2);
\end{tikzpicture}
alin/line between the edges of two nodes ( LaTeX)
\usetikzlibrary{shapes}
\begin{tikzpicture}
\draw (0,0) node(a) [rectangle, draw] {a}
(3,-1) node(b) [circle, draw] {b};
\draw (a) -- (b);
\end{tikzpicture}
Christopher Morley/word wrap long line Java to limited line length with explicit backslashes ( python)
import string
def wrap(text, width):
"""
A word-wrap function that preserves existing line breaks
and most spaces in the text. Expects that existing line
breaks are posix newlines (\n).
Inserted newlines will appear with a backslash instead.
"""
return string.replace(string.replace(string.replace(string.replace(
string.replace(
reduce(
lambda line,
word,
width=width: '%s%s%s' %
(line,
' \n'[(len(line)-line.rfind('\n')-1 +
len(word.split('\n',1)[0]) >= width)],
word),
string.replace(string.replace(
string.replace(text,
".",
".___MARK "),
";",
";___MARK "),
"\n",
"___EOL ").split(' ')
),
"___MARK ", ""),
"___MARK", ""),
"\n", "\\\n"),
"___EOL\\\n", "\n"),
"___EOL ", "\n")
f=open('MyClass.java', 'r') #REPLACE MyClass.java with filename
msg = ""
for line in f:
msg = msg+line
print(wrap(msg,70))
This recipe is based off of http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/148061
I found and used the recipe above, however, I took issue with the results. See, I wanted to use it on a big Java file that had lots of long lines. With extra long package names, and extra long lines containing multiple semicolons without spaces after them, I found it necessary to modify this algorithm to suit my specific purposes.
If you have a line like this:
import com.jobsintheus.vaccinium.controller.ejb.stateful.VacciniumStatefulSessionRemoteHome;
you're going to have problems using the above algorithm, but the one herein does something useful with that - splitting the line on the periods too. It works for semicolons too.
Inserted line breaks will become the visible backslash charater plus the line break.
Otherwise, line breaks that existed before stay as is (with no visible backslash character).
The point is to have the Java code be a readable addition as an input file to (la)tex verbatim.
Joseph Reagle/Textual diffs between word files ( python)
#!/usr/bin/python2.5
# -*- coding: utf-8 -*-
"""Diff two directories of Word documents, providing extra context as well, using antiword and dwdiff."""
# (c) Copyright 2010 by Joseph Reagle
# Licensed under the GPLv3, see <http://www.gnu.org/licenses/gpl-3.0.html>
#
from glob import glob
from os import chdir, mkdir, rename
from os.path import exists, splitext
import re
from shutil import move, rmtree
from subprocess import call, Popen, PIPE
import sys
def create_txts(path):
path_txt = path + 'text/'
if exists(path_txt):
rmtree(path_txt)
mkdir(path_txt)
chdir(path)
for src_fn in glob('*.doc'):
fn, ext = splitext(src_fn)
call(['/usr/bin/antiword', '-w0', src_fn],
stdout=file('text/' + fn + '.txt', 'w'))
pair_diff = r"""[^# ]+\s*(?:#[-].*?[\+]#|[^#]\s+#[\+].*?[-]#)\s*[^# ]+"""
single_diff = r"""[^# ]+\s*(?:#[\+][^#]+[\+]#|#[-][^#]+[-]#)\s*[^# ]+"""
diff_re = re.compile('(' + pair_diff + '|' + single_diff + ')')
footnote_re = re.compile('\d+\)?\+\]')
def create_diffs(old, new):
# dwdiff ~/_joseph/2010/faith/latex-fai/doc/text/reagle_01.txt ~/_joseph/2010/faith-composition/text/reagle_01.txt
old_path = old + 'text/'
new_path = new + 'text/'
chdir(new_path)
for src_fn in sorted(glob('*.txt')):
fn, ext = splitext(src_fn)
f_out = file(fn + '.diff', 'w')
print '\n' + src_fn
output = Popen(['dwdiff', '-w', '#-', '-x', '-#', '-y', '#+', '-z' '+#',
old_path + src_fn, new_path + src_fn], stdout=PIPE) # use # for easier parsing
content = output.communicate()[0]
if content:
for line in content.split('\n'):
if '{Notes begin}' in line:
break
match_obj = diff_re.findall(line)
if match_obj:
f_out.write('\n')
for match in match_obj:
# replace more readable symbols
match = match.replace('#-', '{-') \
.replace('-#', '-}') \
.replace('#+', '[+') \
.replace('+#', '+]')
if not (footnote_re.search(match) or '—' in match or
'–' in match):
f_out.write(match + '\n')
f_out.close()
if '__main__' == __name__:
MY_SRC = '/home/reagle/_joseph/a'
MIT_SRC = '/home/reagle/_joseph/b' # the version sent to compositers.
create_txts(MY_SRC)
create_txts(MIT_SRC)
create_diffs(MY_SRC, MIT_SRC)
Diff two directories of Word documents, providing extra context as well, using antiword and dwdiff.