-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We allow for xypic figures to be created with the same syntax as in LaTeX, using the same approach as for Tikz diagrams. Indeed, we implement this by tweaking the previous Tikz-specific API to handle both cases.
- Loading branch information
Richard Williamson
committed
Feb 1, 2019
1 parent
4f98614
commit 494c311
Showing
7 changed files
with
134 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
\documentclass[12pt]{standalone} | ||
|
||
\usepackage[all]{xy} | ||
|
||
\begin{document} | ||
|
||
$xypic_diagram | ||
|
||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/python3 | ||
|
||
""" | ||
For creating SVG code from a tikz diagram | ||
""" | ||
|
||
import find_block | ||
import os | ||
import subprocess | ||
|
||
class XyPicDiagramException(Exception): | ||
def __init__(self, message): | ||
super().__init__(message) | ||
|
||
def xypic_diagram_processor(xypic_diagram): | ||
xypic_diagram = ( | ||
"\\xymatrix@" + | ||
xypic_diagram + | ||
"}") | ||
diagram_api_path = os.environ["NLAB_DIAGRAM_API_PATH"] | ||
completed_xypic_diagram_process = subprocess.run( | ||
[ diagram_api_path, "xypic" ], | ||
input = xypic_diagram, | ||
text = True, | ||
capture_output = True) | ||
if completed_xypic_diagram_process.returncode != 0: | ||
raise XyPicDiagramException( | ||
completed_xypic_diagram_process.stderr) | ||
return completed_xypic_diagram_process.stdout | ||
|
||
def define_xymatrix_default_size(): | ||
return find_block.Block( | ||
"\\xymatrix{", | ||
"}", | ||
lambda diagram: xypic_diagram_processor( | ||
"=5em{" + diagram), | ||
True) | ||
|
||
def define_xymatrix(): | ||
return find_block.Block( | ||
"\\xymatrix@", | ||
"}", | ||
xypic_diagram_processor, | ||
True) | ||
|
||
def handle_xypic_diagrams(content): | ||
processor = find_block.Processor( | ||
[ define_xymatrix(), define_xymatrix_default_size() ]) | ||
return processor.process(content) | ||
|