Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent with listings Defaults #55

Open
AnzhiZhang opened this issue Dec 28, 2024 · 1 comment
Open

Inconsistent with listings Defaults #55

AnzhiZhang opened this issue Dec 28, 2024 · 1 comment

Comments

@AnzhiZhang
Copy link

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

@wg030
Copy link
Owner

wg030 commented Jan 5, 2025

Thank you for this very detailed issue report.
I am happy to see that you have already found a temporary workaround that you shared with the community.
I guess that you workaround should do the job for now for all people that face the same problem, but I am going to add a new package option to fix this with the next update. However, I am little busy with other stuff right now so that it will likely take a few months.
Nevertheless I guess that this issue is something that should be fixed in a decent way by the package itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants