PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
254 stars 203 forks source link

Feature/tikz preamble #49

Closed Alex-Jordan closed 9 years ago

Alex-Jordan commented 9 years ago

This allows us to put extra packages and other preamble content into the code that goes into a <tikz> tag. Without this, everything you would put into a <tikz> tag goes into the body of a standalone tex document, and the preamble of that tex document is only what is hard coded into extract-tikz.xsl.

There is an example in sample-article.xml using the forest package.

I think this is good, but a side effect of the changes that I made is that no tags within a <tikz> tag are recognized (except the new <tikz-extra-preamble>). My understanding is that formerly, only text (tex code) content would have been inside a <tikz> tag, so this should be backward compatible.

Alex-Jordan commented 9 years ago

OK, I see the problem now. In the hard copy side, the standalone image file is not used to make the book's pdf. Instead, the tikz code is inserted into the .tex file for the whole book. And that makes my attempt to insert \usepackage{} at this local level a problem.

Why not have the .tex side use the standalone image files too, as the HTML does? If you are outputting HTML anyway, you have already run the mbx script that created both a .pdf and an .svg of the image. Instead of having the tikz code go back into the .tex for the book, the .tex file for the book could just include the .pdf file of the image. It would save compilation time for one thing, but it would also serve my purpose here: to allow special packages at the level of an individual image that needs a special package.

I'll make the adjustments to <tikz> in mathbook-latex.xsl if you don't raise an objection.

rbeezer commented 9 years ago

This looks good. How about the following plan?

Consider as much of this as you have an appetite for. At least: locally allowing packages with an attribute, and getting those options into the latex output. I can do the rest using your work as a model.

Are there other libraries I should just include as "standard"?

Rob

Alex-Jordan commented 9 years ago

Are there other libraries I should just include as "standard"?

pgfplots is quite useful for 2D and 3D plots. I think of tikz for more "graphics primitive" things (not to imply tikz is primitive at all). With pgfplots it's easy to make various Cartesian plots. I believe pgfplots loads tikz, so loading it would make a tikz call unnecessary.

Another one might be pgfplotstables, which can do things like access data from a csv file and then do things with that data, both tabular and graphical.

I have a few more thoughts about this:

I'll keep working on this and say something on the pull request thread if I'm at a place for more review.

On Sat, Feb 7, 2015 at 7:26 PM, Rob Beezer notifications@github.com wrote:

This looks good. How about the following plan?

-

Make attributes for the "tikz" element: packages, library, preamble. The "packages" one could be a comma-separated list and MBX would provide the "\usepackage{}" part. Similarly for \tikzlibrary{}. "preamble" would require author to provide everything they want to see.

Do as you have done with xsl/extract-tikz.xsl. I'd prefer the content of the "tikz" element to be all text or totally subdivided with elements, so the "select='.'" was intentional. Notice on the latex side, I sanitize the left margin (using poorly-named templates that clean up sage-code but are really much more general-purpose).

In the latex conversion add to the preamble something like

....../xsl:for-each that writes out the necessary items to the latex preamble. - Likely a long document might use the same packages repeatedly. I'm assuming latex/tikz are smart enough to not be bothered by redundant includes. Also, authors will get tired of specifying them repeatedly. So global "param"'s in xsl/mathbook-common.xsl would make sense. The converters can all access these values (from command line, or in a compatibility layer), though I will need to make it possible for the mbx script to pass them through to xsl/extract-tikz.xsl as suggested in #16 https://github.com/rbeezer/mathbook/issues/16. Consider as much of this as you have an appetite for. At least: locally allowing packages with an attribute, and getting those options into the latex output. I can do the rest using your work as a model. Are there other libraries I should just include as "standard"? Rob — Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-73395185.

Alex Jordan Mathematics Instructor Portland Community College

Alex-Jordan commented 9 years ago

OK, I'm ready for a review. There are some things that are not right for sure, and some other things that you may disagree with (and if so, I'm happy to change).

Issues

rbeezer commented 9 years ago

Looking great. Comments, in order of appearance:

Looking over commits:

Not much energy left tonite to actually test this out. Enough guidance for you to continue working on this? Will your merge of my edits behave when I try to pull this onto my repo?

Alex-Jordan commented 9 years ago

OK, I've done some more things.

Alex-Jordan commented 9 years ago

Perhaps this is related to your comment. As things are now, the latex code is getting initial characters shaved off at each line if there are tab characters at the beginning of lines. This must be the effect of

    <xsl:call-template name="sanitize-sage">
        <xsl:with-param name="raw-sage-code" select="." />
    </xsl:call-template>

What do you recommend to do about this?

rbeezer commented 9 years ago

Yep, for Sage and Python code the indentation is critical. So I suggest never mixing the two. (I just had this discussion with Chris.)

My editor will "Save with Spaces" and I can tab-away easily while diting, but they never migrate into the source.

Left margin is set by the first non-whitespace character and then it gets consistently eaten of the front of each line (and we can never be certain how big a tab is meant to be).

On 02/15/2015 07:38 PM, Alex Jordan wrote:

Perhaps this is related to your comment. As things are now, the latex code is getting initial characters shaved off at each line if there are tab characters at the beginning of lines. This must be the effect of

|

 /xsl:call-template

|

What do you recommend to do about this?

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-74456130.

rbeezer commented 9 years ago

Dear Alex,

I pulled your branch and looked all through the code. It looks good. About done for the day, so I'll do some actual testing very soon, likely on Wednesday.

Some really minor stuff that I am trying to be picky about:

Rob

Alex-Jordan commented 9 years ago

I removed two end of line characters from two files that were showing up in the git diff, and removed two tabs from one blank line in the sample article. Do you see more white space issues? If you do, would it be possible to comment on them directly in GitHub where they are?

For the second and third bullets, I can try to learn, but I'm not as adept with git as you might guess. I wasn't aware that you can combine commits in the way you suggest. And I'm not really sure what rebasing is. When you pulled the description tag in, I had already been working here. I fetched origin, then pulled origin/dev into this branch. There was a conflict of some sort that I had to correct for, as the commit logs show. I'm guessing that rebasing is some smarter way to merge this with the mathbook-sagenb.xsl edits?

I'm happy to learn how to do these things. It may take me a few more days though.

rbeezer commented 9 years ago

Dear Alex,

Put this through its paces and it looks good to me. Some whitespace in a minute, and I will send you some git ideas off-list and we can learn together.

Are there any more touch-ups you plan/want to do?

I'm thinking we might be able to put latex code for commutative diagrams into one of these? That'd be a great unexpected possibility.

Rob

On 02/16/2015 11:09 PM, Alex Jordan wrote:

I removed two end of line characters from two files that were showing up in the git diff, and removed two tabs from one blank line in the sample article. Do you see more white space issues? If you do, would it be possible to comment on them directly in GitHub where they are?

For the second and third bullets, I can try to learn, but I'm not as adept with git as you might guess. I wasn't aware that you can combine commits in the way you suggest. And I'm not really sure what rebasing is. When you pulled the description tag in, I had already been working here. I fetched origin, then pulled origin/dev into this branch. There was a conflict of some sort that I had to correct for, as the commit logs show. I'm guessing that rebasing is some smarter way to merge this with the mathbook-sagenb.xsl edits?

I'm happy to learn how to do these things. It may take me a few more days though.

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-74626059.

rbeezer commented 9 years ago

Dear Alex,

Whitespace at the end of following lines. Sorry - I didn't bother to figure out how to mark these in GitHub and figued this might work just as well for you anyway. I think all are at the end of the line.

sample-article.xml

extract-latex-image.xsl (highly probable these are my fault)

mathbook-latex.xsl

Rob

On 02/16/2015 11:09 PM, Alex Jordan wrote:

I removed two end of line characters from two files that were showing up in the git diff, and removed two tabs from one blank line in the sample article. Do you see more white space issues? If you do, would it be possible to comment on them directly in GitHub where they are?

For the second and third bullets, I can try to learn, but I'm not as adept with git as you might guess. I wasn't aware that you can combine commits in the way you suggest. And I'm not really sure what rebasing is. When you pulled the description tag in, I had already been working here. I fetched origin, then pulled origin/dev into this branch. There was a conflict of some sort that I had to correct for, as the commit logs show. I'm guessing that rebasing is some smarter way to merge this with the mathbook-sagenb.xsl edits?

I'm happy to learn how to do these things. It may take me a few more days though.

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-74626059.

Alex-Jordan commented 9 years ago

I addressed those white spaces. Also the corresponding ones in extract-tikz.xsl, which was what I copied to make extract-latex-image.xsl.

I don't have any ideas on more for this feature, except I do wonder if the sage scrubbing is appropriate for latex code. If an author doesn't indent their code well, the front bits of each line will get chopped. If they are producing xml->tex->pdf, they'll probably see the issue in their tex file. But if they are producing xml->html, and use the mbx script to make images, the script will just hang when it gets to where it should be converting tex->pdf. I think I just have it there because it was their for <tikz>. Thoughts?

latex-image-code should be able to handle commutative diagrams. Just throw the relevant packages and settings into docinfo/latex-image-preamble, and then you can make a commutative diagram inside <latex-image-code>. You could add one to the sample document. I Googled "LaTeX commutative diagram", and it looks like there are many options. I though xypic was the dominant package for this, but that may be old news. Looks like a lot of people like tikz-cd.

I'll look into combining commits.

On Tue, Feb 17, 2015 at 8:55 PM, Rob Beezer notifications@github.com wrote:

Dear Alex,

Whitespace at the end of following lines. Sorry - I didn't bother to figure out how to mark these in GitHub and figued this might work just as well for you anyway. I think all are at the end of the line.

sample-article.xml

  • Inserted in the preamble to each standalone latex-based image for HMTL SVG output.
  • \pgfplotsset{axis x line = middle,
  • \addplot[

extract-latex-image.xsl (highly probable these are my fault)

mathbook-latex.xsl

Rob

On 02/16/2015 11:09 PM, Alex Jordan wrote:

I removed two end of line characters from two files that were showing up in the git diff, and removed two tabs from one blank line in the sample article. Do you see more white space issues? If you do, would it be possible to comment on them directly in GitHub where they are?

For the second and third bullets, I can try to learn, but I'm not as adept with git as you might guess. I wasn't aware that you can combine commits in the way you suggest. And I'm not really sure what rebasing is. When you pulled the description tag in, I had already been working here. I fetched origin, then pulled origin/dev into this branch. There was a conflict of some sort that I had to correct for, as the commit logs show. I'm guessing that rebasing is some smarter way to merge this with the mathbook-sagenb.xsl edits?

I'm happy to learn how to do these things. It may take me a few more days though.

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-74626059.

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-74812251.

Alex Jordan Mathematics Instructor Portland Community College

Alex-Jordan commented 9 years ago

I squashed commits from 18 down to 9. It looks to me like further squashing could be done, but it would involve re-ordering the commits, and I'm worried that would cause conflicts I'd need to resolve. I found this helpful: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

rbeezer commented 9 years ago

Dear Alex,

Thanks for the whitespace cleanup and for cleaning up my (propogated) messes.

I learned something. When I pulled your squashed branch, I got a big mess on my end. ;-) Not at all your fault, it was an experiment and that was a high-probability outcome. I trashed the mess and pulled as if it was the first time. All good. But I need to learn/think about some things relative to collaboration.

Right - you do not really want to reorder unless you are 100% sure about the lack of dependencies. But I've done it. ;-) Did you consider doing a massive "fixup" into one commit and then editing it back into smaller pieces? While there is semi-rapid development and little documentation, I want the log/history to be especially useful to newcomers.

I would really like to have this contribution be commits like (at most)

and I might even consolidate the three middle ones if it was me.

It looks like you "squash"'ed rather than "fixup"'ed, maybe? The commit messages look like a consolidation.

I could do the roll-up and I think preserve/name you as author so the record is straight. Just let me know.

Rob

rbeezer commented 9 years ago

On 02/17/2015 11:42 PM, Alex Jordan wrote:

I don't have any ideas on more for this feature, except I do wonder if the sage scrubbing is appropriate for latex code. If an author doesn't indent their code well, the front bits of each line will get chopped. If they are producing xml->tex->pdf, they'll probably see the issue in their tex file. But if they are producing xml->html, and use the mbx script to make images, the script will just hang when it gets to where it should be converting tex->pdf. I think I just have it there because it was their for <tikz>. Thoughts?

I'd really, really like to banish tabs from the source. An author sees them as 2 spaces, 4 spaces, 8 spaces depending on their settings. What should we do with that?

One of my (many) goals is really clean (human-readable?) source. Especially since the latex output is your data-liberation guarantee. You can always take your latex and go home. So I want folks to be able to put source code way-indented, but also have it flush-left in latex and html output. The name of the template needs to change (and will). Perhaps I need better error-handling on the mbx script, catch some error codes and suggest tabs could be to blame.

latex-image-code should be able to handle commutative diagrams. Just throw the relevant packages and settings into docinfo/latex-image-preamble, and then you can make a commutative diagram inside <latex-image-code>. You could add one to the sample document. I Googled "LaTeX commutative diagram", and it looks like there are many options. I though xypic was the dominant package for this, but that may be old news. Looks like a lot of people like tikz-cd.

David Farmer has some of these from his own experiments. I can maybe get some good examples from him for the sample article, once your stuff goes in.

davidfarmer commented 9 years ago

For commutative diagrams, among existing papers the most popular package is xypic. I can provide examples.

Mathjax dos not know about xypic. It supposedly knows a simpler AMS package that can only draw rectangular diagrams, but I have had some trouble with that. For SL2X I make an image of the diagram to put in the html version.

On Thu, 19 Feb 2015, Rob Beezer wrote:

On 02/17/2015 11:42 PM, Alex Jordan wrote:

I don't have any ideas on more for this feature, except I do wonder if the sage scrubbing is appropriate for latex code. If an author doesn't indent their code well, the front bits of each line will get chopped. If they are producing xml->tex->pdf, they'll probably see the issue in their tex file. But if they are producing xml->html, and use the mbx script to make images, the script will just hang when it gets to where it should be converting tex->pdf. I think I just have it there because it was their for <tikz>. Thoughts?

I'd really, really like to banish tabs from the source. An author sees them as 2 spaces, 4 spaces, 8 spaces depending on their settings. What should we do with that?

One of my (many) goals is really clean (human-readable?) source. Especially since the latex output is your data-liberation guarantee. You can always take your latex and go home. So I want folks to be able to put source code way-indented, but also have it flush-left in latex and html output. The name of the template needs to change (and will). Perhaps I need better error-handling on the mbx script, catch some error codes and suggest tabs could be to blame.

latex-image-code should be able to handle commutative diagrams. Just throw the relevant packages and settings into docinfo/latex-image-preamble, and then you can make a commutative diagram inside <latex-image-code>. You could add one to the sample document. I Googled "LaTeX commutative diagram", and it looks like there are many options. I though xypic was the dominant package for this, but that may be old news. Looks like a lot of people like tikz-cd.

David Farmer has some of these from his own experiments. I can maybe get some good examples from him for the sample article, once your stuff goes in.

— Reply to this email directly or view it on GitHub.[AAM6LPAibbriN8K1zMiUiO6A6WrKp1iTks5nthNSgaJpZM4DdRbo.gif]

rbeezer commented 9 years ago

Thanks, David. I'll ping you after we get Alex's changes in.

This should become a relative no-brainer for an author (modulo xypic), given Alex's work, and then Chris' "sidebyside" will give even more flexibility about how to display these.

Rob

On 02/19/2015 09:46 AM, davidfarmer wrote:

For commutative diagrams, among existing papers the most popular package is xypic. I can provide examples.

Mathjax dos not know about xypic. It supposedly knows a simpler AMS package that can only draw rectangular diagrams, but I have had some trouble with that. For SL2X I make an image of the diagram to put in the html version.

On Thu, 19 Feb 2015, Rob Beezer wrote:

On 02/17/2015 11:42 PM, Alex Jordan wrote:

I don't have any ideas on more for this feature, except I do wonder if the sage scrubbing is appropriate for latex code. If an author doesn't indent their code well, the front bits of each line will get chopped. If they are producing xml->tex->pdf, they'll probably see the issue in their tex file. But if they are producing xml->html, and use the mbx script to make images, the script will just hang when it gets to where it should be converting tex->pdf. I think I just have it there because it was their for <tikz>. Thoughts?

I'd really, really like to banish tabs from the source. An author sees them as 2 spaces, 4 spaces, 8 spaces depending on their settings. What should we do with that?

One of my (many) goals is really clean (human-readable?) source. Especially since the latex output is your data-liberation guarantee. You can always take your latex and go home. So I want folks to be able to put source code way-indented, but also have it flush-left in latex and html output. The name of the template needs to change (and will). Perhaps I need better error-handling on the mbx script, catch some error codes and suggest tabs could be to blame.

latex-image-code should be able to handle commutative diagrams. Just throw the relevant packages and settings into docinfo/latex-image-preamble, and then you can make a commutative diagram inside <latex-image-code>. You could add one to the sample document. I Googled "LaTeX commutative diagram", and it looks like there are many options. I though xypic was the dominant package for this, but that may be old news. Looks like a lot of people like tikz-cd.

David Farmer has some of these from his own experiments. I can maybe get some good examples from him for the sample article, once your stuff goes in.

— Reply to this email directly or view it on GitHub.[AAM6LPAibbriN8K1zMiUiO6A6WrKp1iTks5nthNSgaJpZM4DdRbo.gif]

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-75099859.

cmhughes commented 9 years ago

Slightly off topic, but perhaps not?....

Rob, if you like clean source code, have you seen latexindent? ( https://www.ctan.org/pkg/latexindent). It's part of texlive and MiKTeX. Disclaimer: I'm the author :)

Sorry to interrupt your conversation--must get back to putting things side by side now ;)

On Thu, Feb 19, 2015 at 6:31 PM, Rob Beezer notifications@github.com wrote:

Thanks, David. I'll ping you after we get Alex's changes in.

This should become a relative no-brainer for an author (modulo xypic), given Alex's work, and then Chris' "sidebyside" will give even more flexibility about how to display these.

Rob

On 02/19/2015 09:46 AM, davidfarmer wrote:

For commutative diagrams, among existing papers the most popular package is xypic. I can provide examples.

Mathjax dos not know about xypic. It supposedly knows a simpler AMS package that can only draw rectangular diagrams, but I have had some trouble with that. For SL2X I make an image of the diagram to put in the html version.

On Thu, 19 Feb 2015, Rob Beezer wrote:

On 02/17/2015 11:42 PM, Alex Jordan wrote:

I don't have any ideas on more for this feature, except I do wonder if the sage scrubbing is appropriate for latex code. If an author doesn't indent their code well, the front bits of each line will get chopped. If they are producing xml->tex->pdf, they'll probably see the issue in their tex file. But if they are producing xml->html, and use the mbx script to make images, the script will just hang when it gets to where it should be converting tex->pdf. I think I just have it there because it was their for <tikz>. Thoughts?

I'd really, really like to banish tabs from the source. An author sees them as 2 spaces, 4 spaces, 8 spaces depending on their settings. What should we do with that?

One of my (many) goals is really clean (human-readable?) source. Especially since the latex output is your data-liberation guarantee. You can always take your latex and go home. So I want folks to be able to put source code way-indented, but also have it flush-left in latex and html output. The name of the template needs to change (and will). Perhaps I need better error-handling on the mbx script, catch some error codes and suggest tabs could be to blame.

latex-image-code should be able to handle commutative diagrams. Just throw the relevant packages and settings into docinfo/latex-image-preamble, and then you can make a commutative diagram inside <latex-image-code>. You could add one to the sample document. I Googled "LaTeX commutative diagram", and it looks like there are many options. I though xypic was the dominant package for this, but that may be old news. Looks like a lot of people like tikz-cd.

David Farmer has some of these from his own experiments. I can maybe get some good examples from him for the sample article, once your stuff goes in.

— Reply to this email directly or view it on GitHub.[AAM6LPAibbriN8K1zMiUiO6A6WrKp1iTks5nthNSgaJpZM4DdRbo.gif]

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-75099859.

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-75108315.

rbeezer commented 9 years ago

Very nice! I did not know about that. (I knew you had some chops.)

I made an issue to add this step to the mbx script, so it does not get lost. I'll tinker with it soon.

Thanks!

On 02/19/2015 02:16 PM, cmhughes wrote:

Slightly off topic, but perhaps not?....

Rob, if you like clean source code, have you seen latexindent? ( https://www.ctan.org/pkg/latexindent). It's part of texlive and MiKTeX. Disclaimer: I'm the author :)

Sorry to interrupt your conversation--must get back to putting things side by side now ;)

On Thu, Feb 19, 2015 at 6:31 PM, Rob Beezer notifications@github.com wrote:

Thanks, David. I'll ping you after we get Alex's changes in.

This should become a relative no-brainer for an author (modulo xypic), given Alex's work, and then Chris' "sidebyside" will give even more flexibility about how to display these.

Rob

On 02/19/2015 09:46 AM, davidfarmer wrote:

For commutative diagrams, among existing papers the most popular package is xypic. I can provide examples.

Mathjax dos not know about xypic. It supposedly knows a simpler AMS package that can only draw rectangular diagrams, but I have had some trouble with that. For SL2X I make an image of the diagram to put in the html version.

On Thu, 19 Feb 2015, Rob Beezer wrote:

On 02/17/2015 11:42 PM, Alex Jordan wrote:

I don't have any ideas on more for this feature, except I do wonder if the sage scrubbing is appropriate for latex code. If an author doesn't indent their code well, the front bits of each line will get chopped. If they are producing xml->tex->pdf, they'll probably see the issue in their tex file. But if they are producing xml->html, and use the mbx script to make images, the script will just hang when it gets to where it should be converting tex->pdf. I think I just have it there because it was their for <tikz>. Thoughts?

I'd really, really like to banish tabs from the source. An author sees them as 2 spaces, 4 spaces, 8 spaces depending on their settings. What should we do with that?

One of my (many) goals is really clean (human-readable?) source. Especially since the latex output is your data-liberation guarantee. You can always take your latex and go home. So I want folks to be able to put source code way-indented, but also have it flush-left in latex and html output. The name of the template needs to change (and will). Perhaps I need better error-handling on the mbx script, catch some error codes and suggest tabs could be to blame.

latex-image-code should be able to handle commutative diagrams. Just throw the relevant packages and settings into docinfo/latex-image-preamble, and then you can make a commutative diagram inside <latex-image-code>. You could add one to the sample document. I Googled "LaTeX commutative diagram", and it looks like there are many options. I though xypic was the dominant package for this, but that may be old news. Looks like a lot of people like tikz-cd.

David Farmer has some of these from his own experiments. I can maybe get some good examples from him for the sample article, once your stuff goes in.

— Reply to this email directly or view it on GitHub.[AAM6LPAibbriN8K1zMiUiO6A6WrKp1iTks5nthNSgaJpZM4DdRbo.gif]

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-75099859.

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-75108315.

— Reply to this email directly or view it on GitHub https://github.com/rbeezer/mathbook/pull/49#issuecomment-75150305.

Alex-Jordan commented 9 years ago

I created a new branch for all this, and used git diff to bring in the new elements in a controlled manner. I'm sure there was a proper git solution, but this only took me 30 minutes. If https://github.com/rbeezer/mathbook/pull/55 checks out, then this pull request can be closed.

Alex-Jordan commented 9 years ago

Closing this. #55 has been merged.