I would like to use the typewriter package along with another font. I tried to do that with the fontspec package. I wouldn't mind to use the Latin Modern font. However, the style of the font remains in the typewriter package, which I only would like to use in certain cases in the document. Is there a way to do that?








\setmainfont{EB Garamond}

  • 4
    the package was not really set up for this, it might take a few changes (ie copy typewriter.sty and adjust.... getting the main document fonts back is probably easy, but math mode is more or less destroyed by the package so you'd need to move those definitions into a new mathversion and just switch mathversion when you switch to typewriter mode. Sorry I have no time in next few days but maybe this comment gives someone a hint to answer. Commented May 9, 2019 at 21:25

1 Answer 1


A bit of a place-holder answer.

The font is hard-coded in.

A very quick hack, to turn it into a parameter. Without a fontspec interface.

In the main tex file, do:

\newcommand\xattfname{PT Serif} 

And three changes to make in a modified/renamed typewriter2a.sty (save it in the same location as the main file). The commented-out line is the original.

%\font\cmuntt = file:cmuntt.otf at 12pt \cmuntt

\font\cmuntt = "\xattfname "  at 12pt \cmuntt


%              f.name = 'cmtt10x'
                    f.name = '\xattfname '


%              f.fonts = {{ name = 'file:cmuntt', size = size}}
              f.fonts = {{ name = '\xattfname ', size = size}}

Then back in the main file, do:


so the fontname prints in the output.

I used 14pt:


PT Serif


Doesn't work for all fonts (just NFSS ones?).

The randomness might need tweaking, perhaps. It might be a bit hard to read lengthy blocks of such text.

Close-up of Linux Libertine G:

Linux Libertine G

Overall effect: endearingly cute!

And a cup of something for the thesis reader! :)

  • 1
    Hm... I think what OP wants is not change the font of the package to something else, but to limit the scope of the package. Something like \typewriterON...\typewriterOFF. Commented May 15, 2019 at 14:38
  • 1
    Nice answer, +1. I think @PhelypeOleinik is right though, that the OP also would like to switch the typewriter effect on and off, which would require (probably a lot) more changes in the code.
    – Marijn
    Commented May 15, 2019 at 14:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .