When generating presentations in Quarto, monospace font is very big - quarto

I created a presentation in Quarto with code and outputted it to RevealJS and PPTX. The font size for code in RevealJS is sensible, but the font-size in PowerPoint is gigantic, so the same slide looks very different in RevealJS and PPTX.
Is there a configuration to reduce the font size for monospace fonts in PPTX?

I couldn't find a configuration, but I wrote a quick Python script that uses the python-pptx package to change the fonts. I run it after rendering the presentation.
I first set the font in the YAML as Consolas (to make it easier to find):
format:
pptx:
reference-doc: templates/template.pptx
monofont: "Consolas"
from pptx.util import Pt
from pptx import Presentation
prs = Presentation(path)
# text_runs will be populated with a list of strings,
# one for each text run in presentation
text_runs = []
for slide in prs.slides:
for shape in slide.shapes:
if not shape.has_text_frame:
continue
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
if run.font.name == "Consolas":
run.font.size = Pt(12)
prs.save(new_path)

Related

Customizing Body Text and Images using Markdown, Pandoc, Beamer to create PDF Slideshows

I have a series of markdown files that I am turning into slides using Pandoc and the Beamer template. I am creating my own custom Beamer template in order to format those slides.
pandoc --slide-level 2 -fmarkdown-implicit_figures -t beamer --template mytemplate.beamer -o test.pdf *.md
I am struggling with making certain elements look the way I would like them to.
My simplified markdown looks like this:
## Header
Normal Body Text
![Image](images/Image1.png "Image")
Specifically, my images are coming out left justified. I can't figure out how to get them to center. If I remove the -fmarkdown-implicit_figures option, then the images are properly centered, but includes captions that I don't want. Adding that flag eliminates the captions but also eliminates the centering.
At the same time, I want the normal body text to be centered as well. So in the above example I would like the text Normal Body Text to be centered. Again, I can't figure out how to do that. I have managed to center other elements (such as the header), but I can't find an appropriate name for the element that represents normal body text.
Can anyone offer a solution to either of these issues?
I found a way to center the images. It may not be the best option, but this seems to work:
\usepackage{letltxmacro}
% Save the meaning of \includegraphics
\LetLtxMacro\latexincludegraphics\includegraphics
% Update the include graphics command to include centering
\renewcommand{\includegraphics}[2][]{%
\centering
\latexincludegraphics[#1]{#2}}
To ensure the normal text was centered, I used the following, again I am unsure if this is the best way:
% Center Text By Default
\usepackage{ragged2e}
\centering

How do I change text in a python-fu gimp script without changing the font?

I have a master image which I edit in gimp to get the look and feel wanted. I then want to use a python script to produce a bunch of new images with the text (on several different layers) changed. I would like to leave the font, size, italicized or not, etc. alone.
I've successfully changed the text in my batch script with this function:
pdb.gimp_text_layer_set_text(layer, text)
The problem is this also overwrites the font and other text parameters that I had picked out in the master file. Is there a way to change just the text and leave the font alone?
Alternately, a more clunky way would be to try and save everything important about the font before the change and try to reapply it. This is what I've tried:
# Find the text layer
text1_layer = filter(lambda x: x.name == 'text1', im.layers)[0]
# Save the font
font = pdb.gimp_text_layer_get_font(text1_layer)
font_size, font_unit = pdb.gimp_text_layer_get_font_size(text1_layer)
# Set the text
pdb.gimp_text_layer_set_text(text1_layer, tex1_text)
# Restore the font
pdb.gimp_text_layer_set_font(text1_layer, font)
pdb.gimp_text_layer_set_font_size(text1_layer, font_size, font_unit)
Unfortunately, that doesn't seem to work consistently. It looks like the get_font and get_font_size commands retrieve the right font for one of the layers, but not for the others. It doesn't seem to preserve italics etc., and I wouldn't expect it to preserve whether or not text is underlined.
A third option would be to hard code in the font. I would need to go through all the text fields, figure out what the font parameters are and hard code them in for each one. Then, if I redesign the master file (which I will do a lot), I have to repeat the process. This shouldn't be necessary.
I've done a bit more research and found a solution that works for me in gimp, however, it sounds like you should probably be using something other than gimp, such as imagemagick, if you're doing much text editing from a script.
The solution is, when you change text in the gimp editor you need to change the font in the tool dialog box, so it's set as a property of the layer, instead of just selecting the text and changing the font in the floating font box that shows up - that changes the font of the text you selected, but leaves the base font of the text layer unchanged.
In turns out that gimp text functionality is pretty poor, and there are lots of complaints surrounding issues like this online. There is some hope for the future. Apparently gimp supports a markup language for text. You can get the markup for your text this way:
pdb.gimp_text_layer_get_markup(layer)
Unfortunately, there is no set_markup function - even though it's been commented on and requested for 3-5 years now, so don't hold your breath. If such a function existed, then the get_markup and set_markup functions would give a script complete control over text. It doesn't exist, however, so if you want to change pieces of text (eg. to add italics to a word), you have to create separate layers. If all your text is to be formatted the same, you can edit it via script or editor, and as long as you set it in the text layer properties (done via the tool box in the editor, and the only way you can change font in a script), then the set_text function in a script will maintain font, etc.
https://bugzilla.gnome.org/show_bug.cgi?id=724101
http://gimpchat.com/viewtopic.php?f=9&t=10101&p=132782&hilit=change+text+markup#p132782
Not really a satisfactory answer, but too big to post as a comment.
Yes, the text layer API wasn't updated to follow the new capabilities. Actually all the info is in a gimp-text-layer "parasite":
parasites=layer.parasite_list()
if parasites and 'gimp-text-layer' in parasites:
data=layer.parasite_find('gimp-text-layer').data
pdb.gimp_message('Text layer "%s": %s' % (layer.name,data))
This parasite doesn't seem to exist until the image has been saved at least once.
However, even though you can replace the parasite data, it doesn't change the text layer, and to make it worse, it seems that Gimp detects the change, assumes that the layer text data is corrupt, and makes the layer a plain bitmap when saving the image.
Now, poring over the source code, there are mentions of a GDynText plugin that you can find on SourceForge and that advertizes itself as:
GIMP Dynamic Text is a GIMP plug-in that works like the text tool but allows you writing multi-line text and made you able of modifying it later as you want (text/font/font size/color/...).
So you could be lucky, or not...

Marginsize in Latex resume displays dimensions

I'm using Latex to write my resume, however the default margins for the resume doc type are too wide. The best way to correct this is using the anysize package then setting the margin size, however doing so causes the "=.5=.75" to display before my title in the pdf. Here is the header code
% LaTeX resume using res.cls
\documentclass[margin]{res}
% \usepackage[margin=0.75in,bottom=.5in,top=.5in]{geometry}
\usepackage[none]{hyphenat}%%%%
\usepackage{anysize}
\setlength{\textwidth}{5.8in} % set width of text portion
\begin{document}
\marginsize{.5}{.5}{.75}{.75}
% Center the name over the entire width of resume:
\centerline{\large\bf John Doe}
You need to specify the lengths using some unit of measure. For example:
\marginsize{.5in}{.5in}{.75in}{.75in}
However, as mentioned in the anysize README
This package is obsolete. Use the package typearea to define your
margins typographically correct. Use the package geometry or vmargin
for everything else.
My suggestions would be to stick to geometry package for setting your document layout. Also, not to use resume for setting a resumé. There's moderncv as an alternative, or you could do just as well in the default article class.

figure caption centering in nbconvert?

I have cells underneath figures in an ipython notebook that contain figure caption text. I would like them to be centre('center')-aligned. I use "< center >" in the markdown, which gives exactly the appearance I'm after in the notebook. But when nb-converting to latex, the text gets shunted over to the left.
So is there a way to get nbconvert to recognize text alignment in markdown cells when converting to latex?
Thanks.
You have actually asked two different questions:
is there a way to get nbconvert to recognize text alignment in markdown cells
figure caption (centering) in nbconvert
ad 1)
To convert the markdown to latex pandoc is used. Unfortunately, pandoc removes raw html from markdown if converted to latex (if also removes raw latex when converting markdown to html).
So it is not that straight forward to use html tags to format the output in both html and latex. This formatting may be achieved based cell metadata but that is not that trivial currently.
ad 2)
Nevertheless it is possible to create caption like text to work with html and latex.
Here we have to distinguish between caption for pyout or stream data (e.g. Ipython.display.Image) and markdown images.
pyout and stream
A possible approach is to create a Caption class like
class Caption():
def __init__(self,s):
self.s = s
def _repr_html_(self):
return '<center>{0}</center>'.format(self.s)
def _repr_latex_(self):
return '\\begin{center}\n'+self.s+'\n\\end{center}'
which is called after the image. Note that both should be called with the IPython.display.display method, e.g as oneliner
display(Image('image.jpg'),Caption('Figure Caption'))
This approach allows process the captiontext with python, e.g. to add figure numbers.
If you want to add such a caption to a matplotlib plot, it is a bit more tricky as the wrong ordering has to be overcome. A possible approach is to plot using this snippet
%matplotlib inline
plt.plot([1,2])
f=plt.gcf()
plt.close()
display(f,Caption('Plot'))
It may be noted the the default latex template of IPython 1.x doesn't play well with this approach, as here, image and caption are only loosely coupled and thus, vertical space might be included during latex compiling. The latex_basic template works much better. In IPython master the default templates are working fine.
markdown images
Markdown allows to use images like
![Caption](/files/image)
When converting to latex pandoc can take the Caption part and create a real latex caption.
Similar, when converting to html the caption gets embedded in a caption class to be easily styleable using css.
However, currently IPython requires a "/files/" prefix which is currently not removed, thus the image file won't be found by latex. (Fixed by now)
Be aware that these markdown image calls do not embed but only link the image into the ipynb file, therefore, the image has to remain available.

Latex color box inline with text

I'm trying to put together a LaTeX color box. The xcolor package \fcolorbox seem to be what I want, but I can't get the rendering quite correct. When I use
\fcolorbox{black}{red}{}
it renders a small box sunken to the bottom of the text line. The best I've managed to do is to fake it with a similar text color:
\fcolorbox{black}{red}{\textcolor{red}{--}}
However, I'm worried that this won't render correctly in all situations with defined colors. Is there a way I can declare an empty text box with full in-line text height? Is there another solution?
I'm basically looking for the code that produces the color boxes all through the document at ftp://ftp.dante.de/pub/tex/macros/latex/contrib/xcolor/xcolor.pdf. The boxes I'm referring to are used throughout, but the first instance is on page 4. Thanks.
The xcolor.dtx file in the same directory as the pdf contains the source for the package and the source for the documentation. The relevant bits from the source for the documentation:
\def\testclr#1#{\#testclr{#1}}
\def\#testclr#1#2{{\fboxsep\z#\fbox{\colorbox#1{#2}{\phantom{XX}}}}}
...
(Answer: 40\% \testclr{green} $+$ 60\% \testclr{yellow} $=$ \testclr{green!40!yellow}, e.g., |\color{green!40!yellow}|)
Basically, use \phantom{} on the contents of your color box, and make sure that at least one of the phantom characters is full-height.
Also, https://tex.stackexchange.com/

Resources