Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeXImage.pm #606

Merged
merged 8 commits into from
Feb 12, 2022
Merged

LaTeXImage.pm #606

merged 8 commits into from
Feb 12, 2022

Conversation

Alex-Jordan
Copy link
Contributor

@Alex-Jordan Alex-Jordan commented Sep 16, 2021

This renames TikZImage.pm as LaTeXImage.pm, and makes it so other kinds of images (not necessarily tikz) can be used. It changes PGtikz.pl accordingly, and unless I made a mistake, any problem or macro that relies on PGtikz.pl should still work with no changes.

It adds PGlateximage.pl as the more general version of PGtikz.pl. There are two sample problems that use it in t. One makes an xypic image, one makes a circuittikz image.

There will be a webwork2 PR to go along with this.

@Alex-Jordan Alex-Jordan changed the title LaTeXImage.pl LaTeXImage.pm Sep 16, 2021
Copy link
Member

@drgrice1 drgrice1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few issues here.

Also, please remove the "legacy" comments. The tikz code is not legacy. That is an invalid declaration as that code is still valid and has not been replaced with new code that takes care of its functionality. If anything the new code is experimental.

macros/PGtikz.pl Outdated Show resolved Hide resolved
if ($self->environment->[0] eq 'tikzpicture') {
return &$self('texPackages', ['tikz',@$_[0]]) if ref($_[0]) eq "ARRAY";
return &$self('texPackages', ['tikz']);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code does not work. When the problem author calls this method for the object with an array of packages the texPackages is set to be a reference to the array containing the 'tikz' tex package as well as the additional tex packages requested. However, when this method is later called by this perl package in the header subroutine the additional packages are wiped out and replaced with only the 'tikz' tex package as at that point the array argument is not present.

I recommend that you delete this added code, and add the 'tikz' package as before on what is now line 151 conditional on $self->environment->[0] eq 'tikzpicture'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be any attempt to avoid loading tikz twice? We will automatically load it if environment->[0] eq 'tikzpicture'. But the author might include tikz in texPackages() too. The complication is they might load it as a string or as an array ref that includes package options. So it's a little harder to check if the author is explicitly loading it too.

If it means anything, environment only exists so that PGtikz.pl can use it to maintain automatic wrapping of the tikzpicture environment. If I were making this from scratch, I would just expect authors to write \begin{...}...\end{...} in the tex() part. So I don't expect authors to use environment directly. But it's there, so they might.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would not be a bad idea to check to avoid loading it twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did as you suggested, and then also implemented a check for if tikz is already used. Maybe you can see a simpler way. I turned the array of texPackages (a mix of strings and array refs) into a hash. Each key is a tex package name the author provided. The value from each key is 0 or 1, depending on if it matches 'tikz'. Then the check is boolean on $istikzused{'tikz'}. The result will either be undefined if the author did not include tikz, or 1 if they did.

macros/PGlateximage.pl Outdated Show resolved Hide resolved
@pstaabp
Copy link
Member

pstaabp commented Sep 16, 2021

The two examples provided works, however, I'm trying to run some existing problems that worked with the tikzImage code before, and am unsuccessful. Clearly, I need to adapt to the new API, however, this will need to be done with any tikzImage code currently written, correct?

Are we just hoping that there aren't a lot of problems out there yet? @Alex-Jordan, do you have a plan for this?

@drgrice1
Copy link
Member

@pstaabp: No, existing problems should not need to be changed. They should just work.

@pstaabp
Copy link
Member

pstaabp commented Sep 16, 2021

@drgrice1 Are your original tikzImage problems working under this branch?

@drgrice1
Copy link
Member

Most of them are working. However, any problem that adds an additional tex package fails. See my review comments.

@pstaabp
Copy link
Member

pstaabp commented Sep 16, 2021

The ones that are failing are adding pgfplots.

If we include this package, then there are two ways of including tikz images. That seems confusing to authors. If we are keeping the current tikz image macro (PGtikz.pl) and added a new one that also creates tikzimages, I'm questioning if that's good move.

@drgrice1
Copy link
Member

I believe it is a good move. The PGtikz.pl macro takes care of adding the things needed for tikz images, and so is more convenient for is purpose. Also, it is certainly needed for backwards compatibility.

@pstaabp
Copy link
Member

pstaabp commented Sep 16, 2021

Even though it's not in the nature of webwork to deprecate things, perhaps we can deprecate PGtikz.pl then.

@drgrice1
Copy link
Member

No. I completely disagree.

@Alex-Jordan
Copy link
Contributor Author

@pstaabp Can you post a problem that was working before, but does not work now? I'll include it in revising things today.

The objective here is to (a) open up image-making to LaTeX tools beyond tikz while (b) not messing up problem files (or macros like parserGraphTool.pl) that use PGtikz.pl. And (c) trying to do it without having two .pm files that have 95% code overlap. I think it will work once the issues raised are ironed out.

@drgrice1
Copy link
Member

@Alex-Jordan: Here is a problem that uses pgfplots that worked before this pull request, but does not now.
tikzWPackage.zip

@Alex-Jordan
Copy link
Contributor Author

Ready for more review. I also added a 3rd test problem in t/tikz_test that is essentially the problem you sent me that uses pgfplots.

lib/LaTeXImage.pm Outdated Show resolved Hide resolved
Co-authored-by: Glenn Rice <47527406+drgrice1@users.noreply.github.com>
@pstaabp pstaabp self-requested a review September 20, 2021 12:51
Copy link
Member

@drgrice1 drgrice1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good now. It think that you have addressed all of the concerns that I raised. I will go ahead and merge this.

@drgrice1
Copy link
Member

Oh wait. I need to test those that add packages yet.

@drgrice1
Copy link
Member

Nevermind, I did. Merging.

@drgrice1 drgrice1 merged commit 9eceb2c into openwebwork:develop Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants