Skip to content

Inconsistent with listings Defaults #55

@AnzhiZhang

Description

@AnzhiZhang

Issue Description

I noticed that the package defines custom box styles to align with the Julia online documentation. However, this leads to inconsistencies when using listings with other programming languages.

MVE

\documentclass{article}

\usepackage{listings}
\let\Bbbk\relax
\usepackage[autoload=false, theme=default-plain]{jlcode}

\begin{document}

text1

\begin{jllisting}[language=julia, style=jlcodestyle]
using TypedMatrices
A = Hilbert(5)
\end{jllisting}

text2

\begin{lstlisting}[language=julia, style=jlcodestyle]
using TypedMatrices
A = Hilbert(5)
\end{lstlisting}

text3

\begin{lstlisting}[language=python]
import os
print(os.getcwd())
\end{lstlisting}

text4

\end{document}

Output

image

Additionally, setting certain document properties such as width can cause errors. For example, when using acmart with ``\begin{lstlisting}[language=julia, style=jlcodestyle]`, code blocks may disappear entirely:

\documentclass[acmsmall,screen,dvipsnames]{acmart}

Output

image

Cause Analysis

The issue seems to be related to the aboveskip setting in the jlcodeblockstyle:

% gerneral style for the code block
\lstdefinestyle{jlcodeblockstyle}{%
basicstyle={\loadthemecolors\color{jlstrnum}\jlbasicfont},
keywordstyle={[1]\color{jlkeyword}\bfseries},
keywordstyle={[2]\color{jlliteral}},
keywordstyle={[3]\color{jlbuiltin}},
keywordstyle={[4]\color{jlmacros}},
keywordstyle={[5]\color{jlfunctions}},
commentstyle={\color{jlcomment}},
stringstyle={\color{jlstrnum}},
identifierstyle={\color{jlbase}},
showstringspaces=false,
upquote=true,
tabsize=4,
aboveskip={1.5\baselineskip}, belowskip={1.5\baselineskip}
}

Similarly, the margins defined in the box styles may contribute to the problem:

\lstdefinestyle{jlcodeboxdfltstyle}{%
backgroundcolor=\color{jlbackground}, rulecolor=\color{jlrule},
frame=single, frameround=tttt,
columns=fixed,
basewidth=\bfem,
linewidth=\columnwidth,
xleftmargin=\xmrgn, xrightmargin=\xmrgn,
framexleftmargin=0.5\bfem, framexrightmargin=0.5\bfem
}

Workaround

To resolve these issues temporarily, I renewed the styles as follows:

% renew style for julia code
\lstdefinestyle{jlcodeblockstyle}{%
basicstyle={\loadthemecolors\color{jlstrnum}\jlbasicfont},
keywordstyle={[1]\color{jlkeyword}\bfseries},
keywordstyle={[2]\color{jlliteral}},
keywordstyle={[3]\color{jlbuiltin}},
keywordstyle={[4]\color{jlmacros}},
keywordstyle={[5]\color{jlfunctions}},
commentstyle={\color{jlcomment}},
stringstyle={\color{jlstrnum}},
identifierstyle={\color{jlbase}},
showstringspaces=false,
upquote=true,
tabsize=4,
% aboveskip={1.5\baselineskip}, belowskip={1.5\baselineskip}
}
\lstdefinestyle{jlcodeboxnostyle}{%
columns=fixed,
basewidth=\bfem,
linewidth=\columnwidth,
% xleftmargin=\xmrgn, xrightmargin=\xmrgn,
% framexleftmargin=0.5\bfem, framexrightmargin=0.5\bfem
}

Output

image

Feature Request

While aligning with the Julia online documentation is reasonable, it may be necessary to use listings for multiple languages in a single article. Moreover, the font and styles applied by the package differ slightly from the default listings output, which can cause inconsistencies.

To address this, it would be helpful to introduce an option allowing the package to provide Julia language support and syntax highlighting without enforcing additional box styles or overriding existing listings settings.

Related Issue

See also: #16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions