-
Notifications
You must be signed in to change notification settings - Fork 31
img
All markup languages supported by MarkDoc can include images from the disk or internet in the dynamic document. For example, if you are writing with Markdown:
![image description](path/to/the/image)
if you are writing with LaTeX:
\includegraphics{path/to/the/image}
and if you are writing with HTML:
<img src="oath/to/the/image" >
And to add an image dynamically, you can use the txt
command to
write the markup syntax:
txt ![image description](path/to/the/image)
Using a markup language for importing the an image requires two steps:
- saving a graph from Stata to the disk
- including the graph to the dynamic document
This procedure can be further simplified, using the img
command which can automatically capture the current
graph from Stata and include it in the dynamic document. This command is borrowed from the
Weaver package.
To make MarkDoc a suitable literate programming package for teaching statistics,
even in introductory courses, the img
command was written to eliminate the
need of learning a markup language for importing and styling images in the dynamic document.
The command can:
- Automatically capture the current graph from Stata and include it in the dynamic document
- Include a figure from the disk/internet in the dynamic document
- Resize the width and the height of the image in the dynamic document
- Align the image to the left (default) or center of the document
- Add a graph description
Import graphical files in the dynamic document
img [using filename] [, markup(str) title(str) width(int) height(int) left center ]
Automatically include the current graph from Stata in the dynamic document
img [, markup(str) title(str) width(int) height(int) left center ]
Options | Description |
---|---|
markup(str) | specify the markup language that should be added to the smcl log |
tittle(str) | specify a header string (title) for the figure |
width(int) | define the width of the figure |
hight(int) | define the hight of the figure |
left | aligns the figure to the left-side of the dynamic document (default) |
center | aligns the figure to the center of the dynamic document |
The img
command prints the required markup language in the smcl log to import a figure in the
dynamic document. If the filename
is not specified, img
automatically captures the current graph
from Stata and includes it in the dynamic document. For example:
. sysuse auto
. histogram price
. img
>![](Weaver-figure/figure_2.png)
In this example, img
has stored the current graph in a directory called Weaver-figure and then
prints a markup syntax for importing the image in the dynamic document. If you are writing the documentation
using LaTeX, you have to change the markup language using the markup()
option:
. img, markup(latex)
>\begin{figure}[h]
>\centering
>\includegraphics[width=350px, height=250px]{Weaver-figure/f
> igure_3.png}
>\end{figure}
So instead of writing this LaTeX code for including the image, you just have used a simple command. As you
see by default, the image is imported with width=350
and height=250
pixels. You can also resize the
figure using the width
and height
options. This time, I use the HTML markup as example:
. img, markup(html) width(400) height(300)
><img src="Weaver-figure/figure_4.png" class="center" width="400" height="300" >
Unfortunately, markdown is a vey simplified markup language and it does not allow you to resize the image. Therefore, if you want an image with a particular size you should use the second approach, namely, saving exporting your figure with a particular size and then importing it in the dynamic document. However, this is only necessary in the html format. So if you are intending to produce pdf. slide, tex, docx, or odt from a markdown file, you don't have to worry about an oversized file. MarkDoc takes care of that.
Finally, if you want to add a description to the graph or center
the graph in the document, you can use the
title()
and center
options respectively. These options will add the required markup to style your figure
respectively. See the Examples for further demonstrations.
The img
command adds the required markup syntax for importing a graph to the log. The default markup language is Markdown. Therefore, if you are using a different markup language such as HTML or LaTeX, you should specify that using the markup()
option.