5

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?

\documentclass{scrartcl}

\usepackage{lmodern}

\providecommand\ttgreyone{0.4}
\providecommand\ttgreytwo{0.5}
\providecommand\ttrotatebold{12}
\providecommand\ttdownbold{20000}
\providecommand\ttrightbold{35000}
\providecommand\ttdownshifttwo{20000}

\providecommand\ttrotatenormal{8}
\providecommand\ttrightnormal{20000}
\providecommand\ttdownnormal{20000}

\usepackage{typewriter}

\usepackage[normalem]{ulem}     

\usepackage{fontspec}
\usepackage{lipsum}

\setmainfont{EB Garamond}


\begin{document}
\lipsum[1-2]    
\end{document}
  • 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. – David Carlisle May 9 at 21:25
5

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} 
\usepackage{typewriter2a}

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

and

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

and

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

Then back in the main file, do:

\fontname\font
\lipsum[1-2]    

so the fontname prints in the output.

I used 14pt:

Tinos

PT Serif

Raleway

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. – Phelype Oleinik May 15 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 May 15 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.