General ⇒ Insert bash code - WYSIWYG?
Insert bash code - WYSIWYG?
Hi. I am trying to insert bash code and I make use of a lot of special characters in lots of different order: e.g. {\([^"]\+\)}.*/\1/p$#@ and more.
I have come to the conclusion, that I simply cannot create a good solution for syntax highlighting, and therefore I just want LaTeX to print my exact text as WYSIWYG.
Is there any way to do this using lstlisting?
I have come to the conclusion, that I simply cannot create a good solution for syntax highlighting, and therefore I just want LaTeX to print my exact text as WYSIWYG.
Is there any way to do this using lstlisting?
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Insert bash code - WYSIWYG?
You knwo, you have to tell us where the problem is. You have just the right tool for the task.
Code: Select all
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=bash]
mv *.tex ./texfiles
^\(.*\)\n\1$
awk '/\(c[ad]+r x\)/ { print }' sample
{\([^"]\+\)}.*/\1/p$#@
\end{lstlisting}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Insert bash code - WYSIWYG?
Okay, I will try. My current attempt looks like this:
I am using tcolorbox and listings to format my listings.
It looks like this:
I get the errors:
Package Listings Error: Couldn't load requested language. \end{codeBash}
Package Listings Error: language bash undefined. \end{codeBash}
However in the listings documentation http://mirrors.dotsrc.org/ctan/macros/l ... stings.pdf
bash should be supported.
Code: Select all
\begin{codeBash}[]
#!/usr/bin/env bash
#Name of output without guid
JsonOutputProperty=output
#Name of input without guid
JsonInputProperty=input
#Path to the FMU to chain
FmuPath=$1
#"fmus/performance/integrate"
#cat ${FmuPath}/modelDescription.xml
echo "${FmuPath}"
#FMU base name taken from directory
FmuBaseName=$(basename $FmuPath)
#Destination folder for the new FMUs
FmuDestFolder=$2
#"fmus/performance/test"
#Basepath to insert in FMUs without FMU name
ConfigFmuBasePath=$3
#../fmus/performance/
#Path to initial config file
ConfigJsonPath=$4
#Types of libraries
LibraryTypes=("dll" "dylib" "so")
#Guid of the FMU
#FmuGuid=$(sed -n 's/.*guid="{\([^"]\+\)}.*/\1/p' $FmuPath/modelDescription.xml)
FmuGuid=`grep -oh 'guid="{\([^"]\+\)}"' "${FmuPath}/modelDescription.xml" | sed 's|guid=||g' | tr -d '"' | tr -d '{' | tr -d '}'`
#FmuGuid=`echo '${FmuPath}/modelDescription.xml'`
echo $FmuGuid
echo Create output config
cp $ConfigJsonPath performance.json
ConfigJsonPath=performance.json
mkdir -p $FmuDestFolder
END=$5
for i in $(seq "$END")
do
#Copy the existing FMU to a new directory
NewFmuPath="${FmuDestFolder}/$(basename $FmuPath)$i"
echo "BLAA $NewFmuPath"
rm -rf $NewFmuPath
cp -r $FmuPath $NewFmuPath
echo "Copied FMU from $FmuPath to $NewFmuPath"
#Change the library names so e.g. integrate.dll becomes integrate1.dll
for type in ${LibraryTypes[@]}
do
for lib in $(find $NewFmuPath -iname '*.'"$type")
do
NewLibFileName=$(dirname $lib)/${FmuBaseName}${i}.${lib##*.}
echo Renaming ${lib} to ${NewLibFileName}
mv $lib $NewLibFileName
done
done
#Replace the old GUID with the new guid in the modelDescription.xml file
newGuid="$FmuGuid$i"
sed -i.kk "s/$FmuGuid/$newGuid/g" "$NewFmuPath/modelDescription.xml"
echo "Replaced guid in modelDescription.xml with $newGuid"
#New FMU in config.json
FmuConfigAppend=".fmus |= (.+ [\"$ConfigFmuBasePath$FmuBaseName$i\"] | unique)"
#New connection in config.json
if [ $i != 1 ]; then
CONGUID="$FmuGuid"$(($i-1))
else
CONGUID=$FmuGuid
fi
#Create the new config.json file
FmuConnectionAppend=".connections.\"{$CONGUID}.int1.$JsonOutputProperty\" = [\"{$newGuid}.int1.$JsonInputProperty\"]"
"jq" "$FmuConnectionAppend | $FmuConfigAppend" "$ConfigJsonPath" > "$newGuid.json"
mv -f "$newGuid.json" "$ConfigJsonPath"
echo "Appended the new FMU to fmus and connections in config.json"
done
exec $SHELL
\end{codeBash}
It looks like this:
Code: Select all
\lstdefinestyle{bash}{
rulesepcolor=\color{black},
language=bash
}
\newtcblisting{codeBash}[1][]{%
title = {Bash},
listing options={style=bash,{#1}}
}
Package Listings Error: Couldn't load requested language. \end{codeBash}
Package Listings Error: language bash undefined. \end{codeBash}
However in the listings documentation http://mirrors.dotsrc.org/ctan/macros/l ... stings.pdf
bash should be supported.
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Re: Insert bash code - WYSIWYG?
I provided a minimal working example showing that bash code is supported by listings. The example is compilable and you can check that it works. You posted a code snippet, which is quite useless for me. Make it easier for helpers by providing testable compilable code.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Insert bash code - WYSIWYG?
Finally solved it!
And Johannes_B, sorry for not creating a MWE. Trying to create one actually solved my problem.
It consisted of two things:
First issue:
I had four files in the same folder as the master.tex: lstdoc.sty, lstlang1.sty, lstlang2.sty, lstlang3.sty. Renaming these fixed the first issue of not being able to find the bash language.
Second issue:
I had escapeinside=||, and I use || as part of the shell script.
Thank you. That took up a lot of time!
And Johannes_B, sorry for not creating a MWE. Trying to create one actually solved my problem.
It consisted of two things:
First issue:
I had four files in the same folder as the master.tex: lstdoc.sty, lstlang1.sty, lstlang2.sty, lstlang3.sty. Renaming these fixed the first issue of not being able to find the bash language.
Second issue:
I had escapeinside=||, and I use || as part of the shell script.
Thank you. That took up a lot of time!
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Re: Insert bash code - WYSIWYG?
Nice to know you solved your problem, congratulations.
The every day work of a LaTeX helper is boiling down code that gives errors to a minimal working example. That is the only way to point out an error for sure. As you noticed, the process of boiling down does take a while (you will get faster with experience), but if helpers do all the work, it is a bit unfair. And it is a good feeling to find an error, so everybody should feel that.
The every day work of a LaTeX helper is boiling down code that gives errors to a minimal working example. That is the only way to point out an error for sure. As you noticed, the process of boiling down does take a while (you will get faster with experience), but if helpers do all the work, it is a bit unfair. And it is a good feeling to find an error, so everybody should feel that.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Insert bash code - WYSIWYG?
Thank you for posting the solution and marking as solved!
The pipe symbol | is indeed important for bash.
Stefan
The pipe symbol | is indeed important for bash.

Stefan
LaTeX.org admin