Upright punctuation independent from font style

(copy of my answer on c.t.t.)

It is possible with a virtual font: You can create one that takes its punctuation symbols from the roman font. With pdflatex it would need a few hours work (more if you also want to fine tune the kerning) and some knowledge about fonts in general and fontinst in particular. With lualatex is could be done a bit faster.

You can also make the punctuations symbols active and define them to switch to \upshape. But be aware that this is dangerous -- you can break other commands. E.g. period and dot are often used in numbers.

 \documentclass{book}
 \usepackage[english]{babel}
 \usepackage[T1]{fontenc}
    %\usepackage[T1,mtbold]{mathtime}
 \usepackage{times}
  \defineshorthand{.}{\textup{.}}
  \defineshorthand{,}{\textup{,}}
  \defineshorthand{;}{\textup{;}}

 \useshorthands*{,}
 \useshorthands*{.}
 \useshorthands*{;}
 \begin{document}
 \itshape abc, abc; abc.

 \shorthandoff{,}\shorthandoff{.}\shorthandoff{;}
  abc, abc; abc.

 \end{document}

enter image description here


You can use the LuaTeX post_linebreak_filter for that.

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{times}

\usepackage{luacode}

\begin{luacode*}
function table.contains(t, k)
    for _, v in pairs(t) do
        if v == k then
            return true
        end
    end
    return false
end

function upright_punctucation(head)
    -- Traverse vertical list
    for line in node.traverse_id(node.id("hhead"),head) do
       -- Traverse horizontal list
       for glyph in node.traverse_id(node.id("glyph"), line.head) do
           -- Check if the glyph is
           --                   (   )   ,   :   ;
           if (table.contains({ 40, 41, 44, 58, 59 }, glyph.char)) then
               -- and change its font to upright.
               -- (this is not so generic, 15 just happens to be upright)
               glyph.font = 15
           end
       end
    end
    return head
end

luatexbase.add_to_callback("post_linebreak_filter",upright_punctucation,"upright_punctucation")
\end{luacode*}

\begin{document}
\itshape Cool animals: Wombat, Capybara; Duck and Dove (no Pigeons).
\end{document}

enter image description here