GithubHelp home page GithubHelp logo

Comments (8)

josephwright avatar josephwright commented on July 21, 2024

Drat: I had hoped to avoid having to manually save/restore stuff as this more-or-less relies on internals of how dvips sets things up. But I can't think of another way around this other than using the approach pgf does - I guess I'll need to adjust.

from latex3.

davidcarlisle avatar davidcarlisle commented on July 21, 2024

Not sure how safe it is but adding this to the example...

\cs_set_protected:Npn \__draw_backend_scope_begin:
{ \__draw_backend_literal:n {
    @endspecial ~ save ~ @beginspecial } }
\cs_set_protected:Npn \__draw_backend_scope_end:
  { \__draw_backend_literal:n { @endspecial ~ restore ~ @beginspecial} }

produces

image

dvisvgm also manages to understand this dvips syntax enough and the resulting svg looks like

image

from latex3.

josephwright avatar josephwright commented on July 21, 2024

@davidcarlisle Your idea and my original approach to the box insertion share a common issue. By issuing @endspecial, a scope is closed. That means that if a user has a setting before the box, e.g. a transformation or colour change, it would not apply after the box. For example, before the change I've commited,

\documentclass[border=10pt]{standalone}
\usepackage{l3draw}
\begin{document}
\ExplSyntaxOn
  \draw_begin:
    \color_select:n { red }
    \draw_path_circle:nn { 0cm , 0cm } { 1cm }
    \draw_path_use_clear:n { stroke }
    \hbox_set:Nn \l_tmpa_box {foo}
    \draw_box_use:N \l_tmpa_box
    \draw_path_circle:nn { 0cm , 0cm } { 2cm }
    \draw_path_use_clear:n { stroke }
  \draw_end:
\ExplSyntaxOff    
\end{document}

gives the wrong result with dvips. So I think a change is needed: I'll make some more notes in the sources and add a test or two.

from latex3.

josephwright avatar josephwright commented on July 21, 2024

I think things are OK now - testing suggests so.

from latex3.

davidcarlisle avatar davidcarlisle commented on July 21, 2024

I saw as I posted that you'd just done a checkin saving and restoring explicitly (which looks cleaner anyway than relying on dvips output quite so much). but I'm surprised it closes a scope if used as suggested. The idea was you'd end up with

@beginspecial % from dvips
@endspecial,   % from the \special content
save                % from the \special content
@beginspecial % from the \special content
@endspecial,  % from dvips

so the save is in the outer context and the two empty scopes do nothing, then you do the same wtih restore so following text should be in the original scope.

from latex3.

josephwright avatar josephwright commented on July 21, 2024

I meant that if you end up with for example

@beginspecial % from start-of-picture
1.0 0.0 0.0 TeXcolorrgb % from a color
@endspecial,   % from the \special content
save                % from the \special content
@beginspecial % from the \special content
...                      % Content here
@endspecial,  % from dvips

then the content will come out black not red. As a concrete example, using dvips try

\documentclass{article}
\usepackage{l3draw}
\begin{document}
\ExplSyntaxOn
\cs_set_protected:Npn \__draw_backend_scope_begin:
{ \__draw_backend_literal:n {
    @endspecial ~ save ~ @beginspecial } }
\cs_set_protected:Npn \__draw_backend_scope_end:
  { \__draw_backend_literal:n { @endspecial ~ restore ~ @beginspecial} }
\draw_begin:
  \color_select:n { red }
  \draw_scope_begin:
  \draw_scope_end:
  \draw_path_moveto:n { 0cm, 0cm }
  \draw_path_lineto:n { 10cm, 0cm }
  \draw_path_moveto:n { 5cm, 0cm }
  \draw_path_lineto:n { 5cm , 5cm }
  \draw_path_use_clear:n { stroke }
\draw_end:
\ExplSyntaxOff    
\end{document}

with and without the lines commented. (You also see the line thickness revert to the one not set by l3draw.)

from latex3.

josephwright avatar josephwright commented on July 21, 2024

@davidcarlisle BTW, dvips doesn't add @beginspecial automatically, that comes from the \draw_begin: implementation.

from latex3.

davidcarlisle avatar davidcarlisle commented on July 21, 2024

ah if you get stuf between the begin and end that would be bad:, agreed:-)

from latex3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.