I would like to obtain a straight quote, ', when I type ' in my LaTeX input, and a straight double quote, ", when I type " in my LaTeX input. This, everywhere, in every case: normal text, section title, inside a \texttt or a \verb command, … I want to have “nice” quotes only when I input such with my keyboard (which I’ll do myself, thank you).
This questions lists several similar question, but I have not found this specific question: most questions are in the case of XeLaTeX or are about getting straight quotes only in some special case.
I have tried to adapt an answer to the above question to my case. Here is a MWE.
\documentclass{article}
\usepackage{textcomp}
\begin{document}
\newcommand{\algoupquote}{\mbox{\textquotesingle}}
\newcommand{\algoupquotes}{\mbox{\char`\"}}
\begingroup\lccode`\~=`\'\lowercase{\endgroup\let~}\algoupquote
\begingroup\lccode`\~=`\"\lowercase{\endgroup\let~}\algoupquotes
\catcode`\'=\active\catcode`\"=\active
A "“'straight'” quoting".
\texttt{A "'straight' quoting".}
\end{document}
I have several questions.
- Is this code “dangerous”, in the sense that it would be doing something (e.g., declaring new active characters) that will strongly increase the probability of incompatiblity (or strange behavior) with some package that I might want to use one day or another? (I’d rather give up my dreams of taking care of my quotes myself than risking all sorts of problems and long debugging sessions in the future.)
- How can I suitably simplify the above code? In particular, I’d like to replace the
\algoupquotecommand by its definition, but if I do that, I get insulted by LaTeX (if I dare report it, it says “Argument of \UTFviii@three@octets has an extra }”). - Is there a risk of sensibly enlarging the compilation time, for big documents?
- Can I / should I rather declare ' and " active and use something like
\DeclareUnicodeCharacter{0027}{\textquotesingle}? What would be the advantage and drawback?
(I know that XeLaTeX and other LaTeX variants have been designed for treating nicely Unicode input, but I prefer to keep maximal compatibility and use the standard LaTeX that most people use.)

Format|Smart Quotes|None;TeX ligatures,TeX commands,Unicode characters;Apply to selection. – Cicada Dec 23 '19 at 00:59\textquotesingleand\textquotedblwork without any packages; they must be in the kernel. Possibly related: https://tex.stackexchange.com/questions/7735/how-to-get-straight-quotation-marks – Cicada Dec 23 '19 at 02:12\textcomp. I want to use ' in my source, not\textquotesingle(less readable, does not copy-paste to other document formats…). The question you refer to is about XeTeX. – Olivier Cailloux Dec 23 '19 at 10:39tuenc.defis\DeclareTextCommand\textquotesingle \UnicodeEncodingName{\remove@tlig{"0027}}, otherwise you have to switch off tex-ligatures manually to use^^^^0027as straight quote direct from unicode. None of it is applicable to pdflatex because of the small size, in terms of glyph slot numbers, of the legacy font files used by pdflatex. – Cicada Dec 23 '19 at 12:00iftexlogic to determine the engine being used, for true compatibility. Undoing the ligatures (mapping) that TeX automatically applies seems to be what you want to do. But in pdflatex, which encoding/fonts will you get things from?textcompalready does the TS1 encoding for\textquotesingle- there is much juggling required because the character is not in the cmr default font (128 chars only). – Cicada Dec 23 '19 at 12:29\tqsas a shorter version work for what you want in terms of readability? - it then matches with\lqand\rq. This runs under pdflatex:\documentclass{article} \usepackage{textcomp} \newcommand\tqs{\textquotesingle} \begin{document} \tqs{}z\tqs{} \lq{}z\rq{} \end{document}– Cicada Dec 23 '19 at 12:39\'- it prints the acute accents, but you can\renewcommand\'{\textquotesingle}and use it as\'{x}\'(if you don't have any acutes). – Cicada Dec 23 '19 at 13:05\texttt{\fontencoding{OT1}\selectfont\symbol{13}}produces the straight quote in typewriter type". – Cicada Dec 23 '19 at 13:14\'. When I typea, I get the letter a; when I type a comma, I get a comma. When I type a straight quote, I would like to get a straight quote. And so on. As much as reasonably possible, of course. – Olivier Cailloux Dec 23 '19 at 20:01\documentclass{article} \usepackage{textcomp}%for TS1 encoding \newcommand\qa{\begingroup\fontencoding{TS1}\selectfont '\endgroup} \newcommand\qm{\begingroup\fontencoding{T1}\selectfont "\endgroup} \begin{document} 'z' ''z'' "z" \qa{}z\qa{}\qm{}z\qm{}\end{document}– Cicada Dec 24 '19 at 02:34\documentclass{article}\usepackage{textcomp}\usepackage{fonttable}\begin{document} \xfonttable{TS1}{\rmdefault}{\seriesdefault}{\shapedefault}\end{document}and look in position 39; then do a\documentclass{article}\usepackage{fonttable}\begin{document}\xfonttable{OT1}{\rmdefault}{\seriesdefault}{\shapedefault}\end{document}and look in position 39 (and 96). – Cicada Dec 24 '19 at 02:40\documentclass{article} \usepackage[T1]{fontenc} \usepackage{textcomp} \catcode39=\active \let'\textquotesingle \begin{document} A "'straight' quoting". \texttt{A "'straight' quoting".} \end{document}(not sure about side effects). – Marijn Dec 25 '19 at 19:17\catcode\\`=\active \let`\textasciigrave`, I suppose, but this produces an error message, unsurprinsingly.) – Olivier Cailloux Dec 27 '19 at 14:01LaTeX Warning: Command \textquotesingle invalid in math mode. (I don’t mind much that it doesn’t work in math mode as this is text anyway, but I mind that it makes compilation cycle.) – Olivier Cailloux Dec 27 '19 at 14:07