diff --git a/css/components/elements/_media.scss b/css/components/elements/_media.scss index 4f20f7571c..0dda60e841 100644 --- a/css/components/elements/_media.scss +++ b/css/components/elements/_media.scss @@ -16,10 +16,20 @@ iframe.asymptote, // images in containers should grow to fit space .image-box img, -img.contained { +.image-box svg { width: 100%; } +.image-box.image-box__auto-width img, +.image-box.image-box__auto-width svg +{ + max-width: 100%; + width: auto; + margin-left: auto; + display: block; + margin-right: auto; +} + // --------------------------------------------- // images .ptx-content img, .ptx-content svg { diff --git a/examples/sample-article/media/images/new-folder-screenshot.png b/examples/sample-article/media/images/new-folder-screenshot.png new file mode 100644 index 0000000000..7f20d364f4 Binary files /dev/null and b/examples/sample-article/media/images/new-folder-screenshot.png differ diff --git a/examples/sample-article/sample-article.xml b/examples/sample-article/sample-article.xml index 07af90cb74..6287889731 100644 --- a/examples/sample-article/sample-article.xml +++ b/examples/sample-article/sample-article.xml @@ -3306,6 +3306,23 @@ along with MathBook XML. If not, see . +

Images that are given a width (always as a percentage) are scaled to that percentage of their container. Images without a width will be rendered at their natural size if possible and as large as possible if not. This can be seen in these three renderings of the same screenshot:

+ +
+ A new folder with width="100%" + +
+ +
+ A new folder with width="50%" + +
+ +
+ A new folder with no width + +
+

If you have existing images that are vector graphics, then PDF format works best for output and SVG format works best for HTML. The utility pdf2svg works well for converting PDF to SVG. In this case, specify your source as a filename, but leave off the file extension, and the appropriate version will be used for the current output format.

The image below is provided from a PDF file in output, and was converted to an SVG for use with the HTML output. It has been explicitly scaled to a width of 65% of the text width.

@@ -3347,7 +3364,7 @@ along with MathBook XML. If not, see .
Solution to a differential equation - + @@ -3375,7 +3392,7 @@ along with MathBook XML. If not, see .

This next diagram employs some macros that are defined in the usual way in docinfo and are employed to produce the names of some vectors in the labels. The blue line is colored blue by a global declaration, also in docinfo.

- + @@ -3418,7 +3435,7 @@ along with MathBook XML. If not, see .

The next diagram is authored with annotations, arranged in a hierarchy of increasing refinement and detail. Each identified graphical component will read its annotation and show it on the screen below the diagram. When a reader clicks on the image, a high-level summary will be read using the author-provided annotation. The down and up arrow keys enable a reader to explore the diagram in more or less detail while the right and left arrow keys reveal features at the same level of detail. When the focus is on the graph, pressing "O" will produce a sonification of the graph.

- + diff --git a/xsl/pretext-common.xsl b/xsl/pretext-common.xsl index ffbd5a4b37..4e9544feee 100644 --- a/xsl/pretext-common.xsl +++ b/xsl/pretext-common.xsl @@ -5462,6 +5462,9 @@ Book (with parts), "section" at level 3 + + + - + -
+
+ + image-box + + image-box__auto-width + + width: @@ -5884,15 +5890,6 @@ along with MathBook XML. If not, see . - - - - - - - - - diff --git a/xsl/pretext-latex-common.xsl b/xsl/pretext-latex-common.xsl index a803112644..c3b6e2ad54 100644 --- a/xsl/pretext-latex-common.xsl +++ b/xsl/pretext-latex-common.xsl @@ -405,6 +405,7 @@ along with MathBook XML. If not, see . + @@ -1384,6 +1385,24 @@ along with MathBook XML. If not, see . + + + + %% Define maxwidth variable for includegraphics + %% recipe from https://texfaq.org/FAQ-grmaxwidth + \makeatletter + + \def\maxwidth{% + \ifdim\Gin@nat@width>\linewidth + \linewidth + \else + \Gin@nat@width + \fi + } + \makeatother + + + @@ -1391,7 +1410,7 @@ along with MathBook XML. If not, see . %% arguments are left-margin, width, right-margin, as multiples of %% \linewidth, and are guaranteed to be positive and sum to 1.0 \tcbset{ imagestyle/.style={bwminimalstyle} } - \NewTColorBox{tcbimage}{mmm}{imagestyle,left skip=#1\linewidth,width=#2\linewidth} + \NewTColorBox{tcbimage}{mmm}{imagestyle,left skip=#1\linewidth,width=#2\linewidth,halign=center} %% Wrapper environment for tcbimage environment with a fourth argument %% Fourth argument, if nonempty, is a vertical space adjustment %% and implies image will be preceded by \leavevmode\nopagebreak @@ -9294,7 +9313,15 @@ along with MathBook XML. If not, see . - \includegraphics[width=\linewidth + \includegraphics[width= + + + \linewidth + + + \maxwidth + + ,angle=