コード例 #1
0
    def testUnderfullVboxWarning(self, l):
        text.text(0,
                  0,
                  r"\parindent=0pt\vbox to 1cm {hello, world, hello, world}",
                  textattrs=[text.parbox(1.9)])
        l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
Underfull \vbox (badness 10000) detected at line 0"""))
コード例 #2
0
    def testUnderfullHboxWarning(self, l):
        text.text(0,
                  0,
                  r"\hbadness=0hello, world, hello",
                  textattrs=[text.parbox(2.5)])
        l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
Underfull \hbox (badness 171) detected at line 0
[]\OT1/cmr/m/n/10 hello, world,"""))
コード例 #3
0
    def testOverfullHboxWarning(self, l):
        text.text(0,
                  0,
                  r"hello, world",
                  textattrs=[text.parbox(30 * unit.u_pt)])
        l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
Overfull \hbox (8.22089pt too wide) detected at line 0
[]\OT1/cmr/m/n/10 hello,"""))
コード例 #4
0
ファイル: test_texmessageparser.py プロジェクト: mjg/PyX
    def testOverfullHboxWarning(self, l):
        text.text(0, 0, r"hello, world", textattrs=[text.parbox(30 * unit.u_pt)])
        l.check(
            (
                "pyx",
                "WARNING",
                r"""ignoring overfull/underfull box:
Overfull \hbox (8.22089pt too wide) detected at line 0
[]\OT1/cmr/m/n/10 hello,""",
            )
        )
コード例 #5
0
ファイル: test_texmessageparser.py プロジェクト: mjg/PyX
    def testUnderfullHboxWarning(self, l):
        text.text(0, 0, r"\hbadness=0hello, world, hello", textattrs=[text.parbox(2.5)])
        l.check(
            (
                "pyx",
                "WARNING",
                r"""ignoring overfull/underfull box:
Underfull \hbox (badness 171) detected at line 0
[]\OT1/cmr/m/n/10 hello, world,""",
            )
        )
コード例 #6
0
def generate_tile(item):
    title = item['title']
    print(title)
    image = item['image']

    if item['quantity'] > 1:
        handle_multiple(item)
        return

    #72dpi is illustrator default
    drawing = svgfile.svgfile(0, 0, 'images%s' % image, parsed=True, resolution=72)
    setEtch(drawing.canvas)
    canvas_size = get_canvas_size(item)
    drawing_size = (drawing.bbox().width(), drawing.bbox().height())

    dir = 'tiles/%s' % item['type']
    if not os.path.exists(dir):
        os.makedirs(dir)
    c = canvas.canvas()

    center = ( (canvas_size[0] - drawing_size[0]) / 2, (canvas_size[1] - drawing_size[1]) / 2 )
    c.insert(drawing, [trafo.translate(center[0], center[1])])

    yMargin = (canvas_size[1] - drawing_size[1]) / 2
    yPos = yMargin - yMargin / 2
    baseline = text.parbox.middle
    textbox = '{\large %s}' % title
    if 'subtitle' in item:
        textbox += '\n\n'
        textbox += item['subtitle']

    if yPos < (unit.t_inch / 2):
        baseline = text.parbox.bottom

    c.text(canvas_size[0] / 2, yPos, textbox, [
            text.halign.boxcenter,
            text.halign.flushcenter,
            text.parbox(canvas_size[0] - .25 * unit.t_inch, baseline = baseline)
    ])

    #draw Cut line
    if CUT_LINE:
        c.stroke(
            path.rect(0, 0, canvas_size[0], canvas_size[1]),
            [ style.linewidth(0.001), color.rgb.red ]
        )

    p = document.page(c, bbox=bbox.bbox(0, 0, canvas_size[0], canvas_size[1]))
    d = document.document([p])
    d.writeSVGfile('%s/%s.svg' % (dir, slugify(title)))
コード例 #7
0
    def flush(self):
        """
        Writes all graphics to the page, preparing it for output.
        
        This method also clears the canvas to allow it to be reused.
        
        This method draws the student and instructor submissions at the top, and places 
        the grading comments below
        """
        from pyx import text
        # Determine the margins relative to US letter
        bdx = max(self.x, 36)
        bdy = max(self.y, 36)
        bdw = min(self.width, 540)
        bdh = min(self.height, 720)

        xoff = (self.width - bdw) / 2.0

        self.submitted.flush()
        self.submitted.scale = 0.45
        yoff = (self.height - bdy -
                self.submitted.height * self.submitted.scale)
        self.submitted.embed(self._canvas, x=xoff, y=yoff)
        self.solution.flush()
        self.solution.scale = 0.45
        yoff = (self.height - bdy - self.solution.height * self.solution.scale)
        self.solution.embed(self._canvas, x=self.width / 2.0, y=yoff)

        header = 'Autograder Comments' if self.title == '' else 'Autograder Comments on ' + self.title
        self._canvas.text(bdx, self.height / 2.0,
                          "{\\Large\\textbf{%s}:} " % header)

        # Internal offset for comments
        yoff = self.height / 2.0 - 30

        # Add the comments
        body = "\large\\noindent "
        frst = True
        for line in self._comments:
            if frst:
                frst = False
            else:
                body += " \\\\"
            body += line
        self._canvas.text(xoff, yoff, body, [text.parbox(bdw)])

        # Store canvas in page list and clear
        self._pglist.append(self._page)
        self.clear()
コード例 #8
0
              path.rlineto(0, ncols*boxsize),
              path.rlineto(-nrows*boxsize, 0),
              path.rlineto(-reducedboxsize*cos(angle), -reducedboxsize*sin(angle)))
c.stroke(p)

for nx in range(ncols):
    x = (nx+0.5)*boxsize
    for ny in range(nrows):
        y = (ncols-ny-0.5)*boxsize
        c.text(x, y, r'\textbf{{{}}}'.format(ny*10+nx),
               [text.halign.center, text.valign.middle])

parwidth = 10.6
inputtemplate = r'\noindent\textcolor{{ex{}color}}{{\bfseries>{{}}>{{}}> {}}}'
resulttemplate = r'\textcolor{{ex{}color}}{{{}}}'
myattrs = [text.valign.top, text.parbox(parwidth)]
textblockdist = 0.5
ytop = ncols*boxsize

for s in ((inputtemplate.format('1', 'a[(0,1,2,3,4), (1,2,3,4,5)]')
           + r'\\[0.1\baselineskip]'
           + resulttemplate.format('1', r'array([1, 12, 23, 34, 45])')
           ),
          (inputtemplate.format('2', 'a[3:, [0,2,5]]')
           + r'\\[0.1\baselineskip]'
           + resulttemplate.format('2', 'array([[30, 32, 35],')
           + r'\\'
           + resulttemplate.format('2', r'\hphantom{array([}[40, 42, 45],')
           + r'\\'
           + resulttemplate.format('2', r'\hphantom{array([}[50, 52, 55]])')
           ),
コード例 #9
0
                          reducedboxsize*sin(angle)),
              path.rlineto(0, ncols*boxsize),
              path.rlineto(-nrows*boxsize, 0),
              path.rlineto(-reducedboxsize*cos(angle), -reducedboxsize*sin(angle)))
c.stroke(p)
for nx in range(ncols):
    x = (nx+0.5)*boxsize
    for ny in range(nrows):
        y = (ncols-ny-0.5)*boxsize
        c.text(x, y, r'\textbf{{{}}}'.format(ny*10+nx), [text.halign.center, text.valign.middle])

parwidth = 10.6
s = r'''\noindent\textcolor{ex2}{\bfseries>{}>{}> a[(0,1,2,3,4), (1,2,3,4,5)]}\\[0.1\baselineskip]
        \textcolor{ex2}{array([1, 12, 23, 34, 45])}
     '''
c.text(-parwidth-0.5, ncols*boxsize, s, [text.valign.top, text.parbox(parwidth)])

s = r'''\noindent\textcolor{ex1}{{\bfseries>{}>{}> a[3:, [0,2,5]]}\\[0.1\baselineskip]
        \textcolor{ex1}{array([[30, 32, 35],}\\
        \textcolor{ex1}{\hphantom{array([}[40, 42, 45],}\\
        \textcolor{ex1}{\hphantom{array([}[50, 52, 55]])}}
     '''
c.text(-parwidth-0.5, ncols*boxsize-1.5, s, [text.valign.top, text.parbox(parwidth)])

s = r'''\noindent\textcolor{ex3}{\bfseries>{}>{}> mask = np.array([1,0,1,0,0,1], dtype=bool)}\\
        \textcolor{ex3}{\bfseries>{}>{}> a[mask, 2]}\\[0.1\baselineskip]
        \textcolor{ex3}{array([2, 22, 52])}
     '''
c.text(-parwidth-0.5, ncols*boxsize-4, s, [text.valign.top, text.parbox(parwidth)])

basename = os.path.splitext(sys.argv[0])[0]
コード例 #10
0
ファイル: polynomial.py プロジェクト: papadopa-cy/jupyter4edu
dx = 0.3
h = 4
w = 6.5
p = path.rect(-dx, -dx, w+2*dx, h+2*dx)
p = deformer.smoothed(0.5).deform(p)
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])
c.fill(p, [color.grey(0.9)])

c1 = canvas.canvas([canvas.clip(p)])
c2 = canvas.canvas()
textcolor = color.hsb(0.6, 0.3, 1)
t = """\Huge
$2x^4+10x^3$

p1 = \{4: 2, 3: 10\}

$5x^2-x+32$

p2 = \{2: 5, 1: -1, 0: 32\}

multiply(p1, p2)
"""
c2.text(0, 0, t, [text.parbox(2*w), textcolor])
c1.insert(c2, [trafo.rotate(20).translated(-0.2*w, 0.9*h)])
c.insert(c1)

t = r'\Large $(2x^4+10x^3)(5x^2-x+32)$'
c.text(w/2, h/2, t, [text.halign.center, text.valign.middle,
                     color.hsb(0.05, 0.9, 0.6)])
c.writeGSfile(device="png16m", resolution=300)
コード例 #11
0
ファイル: test_texmessageparser.py プロジェクト: mjg/PyX
    def testOverfullVboxWarning(self, l):
        text.text(
            0, 0, r"\parindent=0pt\vbox to 1cm {hello, world, hello, world, hello, world}", textattrs=[text.parbox(1.9)]
        )
        l.check(
            (
                "pyx",
                "WARNING",
                r"""ignoring overfull/underfull box:
Overfull \vbox (2.4917pt too high) detected at line 0""",
            )
        )
コード例 #12
0
ファイル: drawer.py プロジェクト: AntipovDen/Matan
# c.stroke(path.line(4, 3, 6, 3), [style.linestyle.dashed])
# c.stroke(path.line(4, 1, 6, 1), [style.linestyle.dashed])
# c.stroke(path.line(4, -1, 6, -1), [style.linestyle.dashed])
# c.stroke(path.line(4, -3, 6, -3), [style.linestyle.dashed])
# c.text(4, 3, r"$$p \in Z$$", [text.parbox(1), text.valign.bottom, text.halign.left])
# c.text(4, 1, r"$$\frac{m + 1}{n} \in Z$$", [text.parbox(1), text.valign.bottom, text.halign.left])
# c.text(4, -1, r"$$\frac{m + 1}{n} + p \in Z$$", [text.parbox(1), text.valign.bottom, text.halign.left])
# c.text(4, -3, r"else", [text.parbox(1), text.valign.bottom, text.halign.left])
#
# c.text(6, 3, r"$$\left[ x = t^N \right], N\textrm{ -- общий знаменатель }m\textrm{ и }n", [text.parbox(10), text.valign.middle])
#
# c.writePDFfile("irrational_scheme_1.pdf")
# exit(0)

c.text(-1, 4, r"$$\int\frac{R(x) dx}{\sqrt{ax^2 + bx + c}}$$",
       [text.parbox(2), text.valign.middle])
c.stroke(path.line(2, 4, 3, 4))
c.stroke(path.line(3, 10, 3, 1))

c.stroke(path.line(3, 10, 4, 10))
c.text(3.6, 10, r"2.1", [text.parbox(0), text.valign.middle])
c.stroke(path.circle(4.35, 10, 0.3))
c.text(
    4.2, 10,
    r"$$\int\frac{P(x) dx}{\sqrt{ax^2 + bx + c}} = Q(x)\sqrt{ax^2 + bx + c} + \lambda \int \frac{dx}{\sqrt{ax^2 + bx + c}},\textrm{ deg} Q(x) < \textrm{deg} P(x)$$",
    [text.parbox(15), text.valign.middle])

c.stroke(path.line(3, 8, 4, 8))
c.text(3.6, 8, r"2.2", [text.parbox(0), text.valign.middle])
c.stroke(path.circle(4.35, 8, 0.3))
c.text(
コード例 #13
0
from pyx import canvas, color, deformer, path, text, trafo, unit

text.set(text.LatexRunner)
text.preamble(r'''\usepackage[scaled=0.85,lining]{FiraMono}
                  \usepackage[utf8]{inputenc}''')
pistring = '3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852'
char_per_line = 25
pistring = ' '.join(
    [pistring[n * char_per_line:(n + 1) * char_per_line] for n in range(10)])
unit.set(xscale=1.45)

c = canvas.canvas()
dx = 0.3
h = 4
w = 6.5
p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx)
p = deformer.smoothed(0.5).deform(p)
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])
c.fill(p, [color.grey(0.9)])
c.text(0, 0, r'\noindent\texttt{{{}}}'.format(pistring),
       [text.valign.bottom, text.parbox(5)])
c.text(0.5 * w, 0.5 * h, r'\Huge $\pi$', [
    text.halign.center, text.valign.middle,
    color.hsb(0.66, 0.8, 1),
    color.transparency(0.2),
    trafo.scale(5.8)
])

c.writePDFfile()
コード例 #14
0
                reducedboxsize * sin(angle)), path.rlineto(0, ncols * boxsize),
    path.rlineto(-nrows * boxsize, 0),
    path.rlineto(-reducedboxsize * cos(angle), -reducedboxsize * sin(angle)))
c.stroke(p)

for nx in range(ncols):
    x = (nx + 0.5) * boxsize
    for ny in range(nrows):
        y = (ncols - ny - 0.5) * boxsize
        c.text(x, y, r'\textbf{{{}}}'.format(ny * 10 + nx),
               [text.halign.center, text.valign.middle])

parwidth = 6
inputtemplate = r'\noindent\textcolor{{ex{}color}}{{\bfseries>{{}}>{{}}> {}}}'
resulttemplate = r'\textcolor{{ex{}color}}{{{}}}'
myattrs = [text.valign.top, text.parbox(parwidth)]
textblockdist = 0.5
ytop = ncols * boxsize + 0.4

for s in ((inputtemplate.format('1', 'a[0, 3:5]') + r'\\[0.1\baselineskip]' +
           resulttemplate.format('1', 'array([3, 4])')),
          (inputtemplate.format('2', 'a[4:, 4:]') + r'\\[0.1\baselineskip]' +
           resulttemplate.format('2', 'array([[44, 55],') + r'\\' +
           resulttemplate.format('2', r'\hphantom{array([}[54, 55]])')),
          (inputtemplate.format('3', 'a[:, 2]') + r'\\[0.1\baselineskip]' +
           resulttemplate.format('3', 'a([2, 12, 22, 32, 42, 52])')),
          (inputtemplate.format('4', 'a[2::2, ::2]') +
           r'\\[0.1\baselineskip]' +
           resulttemplate.format('4', r'array([[20, 22, 24],') + r'\\' +
           resulttemplate.format('4', r'\hphantom{array([}[40, 42, 44]])'))):
    t = text.text(-parwidth - 0.5, ytop, s, myattrs)
コード例 #15
0
ファイル: tmp.py プロジェクト: AntipovDen/Matan
from pyx import canvas, path, deco, style, color, text
from math import sqrt

text.set(text.LatexRunner)
c = canvas.canvas()

c.stroke(path.circle(0, 0, 1))
c.stroke(path.circle(5, 0, 1))
c.stroke(path.circle(15, 0, 1))
c.stroke(path.circle(20, 5, 1))

c.stroke(path.circle(9, 0, 0.1), [style.linewidth.THICK])
c.stroke(path.circle(10, 0, 0.1), [style.linewidth.THICK])
c.stroke(path.circle(11, 0, 0.1), [style.linewidth.THICK])

c.text(0, 0, r'\Huge{1}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(5, 0, r'\Huge{2}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(15, 0, r'\Huge{K}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(20, 5, r'\Huge{0}', [text.parbox(0), text.valign.middle, text.halign.center])

c.stroke(path.curve(1 / sqrt(2), 1 / sqrt(2), 2, 2, 3, 2,  5 - 1 / sqrt(2), 1 / sqrt(2)), [deco.earrow(size=1)])
c.stroke(path.curve(5 - 1 / sqrt(2), -1 / sqrt(2), 3, -2, 2, -2,  1 / sqrt(2), -1 / sqrt(2)), [deco.earrow(size=1)])
c.stroke(path.curve(1 / sqrt(2), 1 / sqrt(2), 1, 5, 10, 5,  19, 5), [deco.earrow(size=1)])
c.stroke(path.curve(5 + 1 / sqrt(2), 1 / sqrt(2), 7, 5, 12, 5,  19, 5), [deco.earrow(size=1)])
c.stroke(path.line(15 + 1 / sqrt(2), 1 / sqrt(2), 20 - 1 / sqrt(2), 5 - 1 / sqrt(2)), [deco.earrow(size=1)])


c.text(2.5, 2.5, r'\huge{$p_1^2$}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(2.5, -1, r'\huge{$p_2^1$}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(2.5, 4, r'\huge{$p_1^0$}', [text.parbox(0), text.valign.middle, text.halign.center])
c.text(8, 3, r'\huge{$p_2^0$}', [text.parbox(0), text.valign.middle, text.halign.center])
コード例 #16
0
ファイル: poster.py プロジェクト: punkdit/fibonacci
y = h-9*dr

#for i in range(30):
#    y0 = y-i*dr
#    if y0 < 0.:
#        break
#    cross(0, y0)

box = c.text(x, y, r"""
Here we consider a two dimensional system with Fibonacci
anyon excitations. %What does this mean?

The total charge enclosed in a region may be measured with possible
outcomes $\tau$ which indicates a Fibonacci anyon charge, or ${\mathbb{I}}$
which indicates vacuum:
""".strip(), [text.parbox(dw-2*m), ])
#print repr(box.height)
#print unit.tocm(box.height)

y -= 5*dr
rect(x+dw/2-1., y-1., 1., 1., r"$\I$ or $\tau$")

y -= 3.*dr
box = c.text(x, y, r"""
Two such measurements commute when the two regions are either disjoint
or one is wholly contained within the other.

The following rules constrain measurment outcomes:
""".strip(), [text.parbox(dw-2*m), ])

y -= 6*dr
コード例 #17
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci

braid(3, 1, trafo.translate(-m-0.5, 0.))
braid(3, 1, trafo.translate(-m-0.5, 1.))

slice(-m, 2.)
c.text(x, 2., r"$\sigma_2^{2}\ket{\psi}$", st)

s = [style.linewidth.Thick, deco.earrow(size=0.2)]
c.stroke(path.line(x, 0.3, x, 1.7), s)
flat = [deco.earrow(angle=170, size=0.1)]
c.stroke(path.line(x, 1.7, x, 0.3), flat+[style.linewidth.Thick])

c.text(x-0.5, -1.0,
    "Braid group acts on states:\ \ \ \ \ \ \ \ \ \  \  ``Schrodinger picture''",
    [text.parbox(4.), text.valign.top, text.halign.flushleft])

# %%%%%%%%%%%%%%%%

x = +0.5

slice(+m, +2.)
c.stroke(path.circle(m-0.25, 2., 0.5), [trafo.scale(1., 0.3, m-0.25, 2.)])
c.text(x, 2., r"$D_3$", st)

slice(+m, 0.)
c.stroke(wiggle, [trafo.translate(m, 0.), trafo.scale(1., 0.4, m, 0.)])

c.text(x, 0., r"$D_3$", st)
c.text(x-0.2, 1., r"$f$", st)
s = [style.linewidth.Thick, deco.earrow(size=0.2)]